//fast
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) x.begin(),x.end()
#define rep(n) for (int i = 0 ; i<n ; i++)
#define pb push_back
const int base = 5e5+7;
ll po2[base];
ll po3[base];
ll a[base];
int n;
bool check(ll ile){
ll pref = 0;
rep(n){
ll p = -1;
ll k = ile;
while (k-p>1){
ll c = (k+p)/2;
if (c*(pref*(ile-c))+po2[c]*(pref+(ile-c))+po3[c]>=a[i]){
k = c;
}else p = c;
}
if (k*(pref*(ile-k))+po2[k]*(pref+(ile-k))+po3[k]<a[i]) return 0;
ile-=k;
pref+=k;
}
if (ile>=0) return 1;
return 0;
}
void solve(int ttt){
cin >> n;
rep(n) cin >> a[i];
int p = 0;
int k = base;
while (k-p>1){
int s = (k+p)/2;
if (check(s)) k = s;
else p = s;
}
cout << k << '\n';
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
po2[0] = 0;
po2[1] = 0;
po2[2] = 1;
po3[0] = 0;
po3[1] = 0;
po3[2] = 0;
po3[3] = 1;
for (int i = 3 ; i<base ; i++){
po2[i] = po2[i-1]+i-1;
}
for (int i = 4 ; i<base ; i++){
po3[i] = po3[i-1]+po2[i-1];
}
int t = 1;
cin >> t;
rep(t) solve(i);
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | //fast #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define all(x) x.begin(),x.end() #define rep(n) for (int i = 0 ; i<n ; i++) #define pb push_back const int base = 5e5+7; ll po2[base]; ll po3[base]; ll a[base]; int n; bool check(ll ile){ ll pref = 0; rep(n){ ll p = -1; ll k = ile; while (k-p>1){ ll c = (k+p)/2; if (c*(pref*(ile-c))+po2[c]*(pref+(ile-c))+po3[c]>=a[i]){ k = c; }else p = c; } if (k*(pref*(ile-k))+po2[k]*(pref+(ile-k))+po3[k]<a[i]) return 0; ile-=k; pref+=k; } if (ile>=0) return 1; return 0; } void solve(int ttt){ cin >> n; rep(n) cin >> a[i]; int p = 0; int k = base; while (k-p>1){ int s = (k+p)/2; if (check(s)) k = s; else p = s; } cout << k << '\n'; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); po2[0] = 0; po2[1] = 0; po2[2] = 1; po3[0] = 0; po3[1] = 0; po3[2] = 0; po3[3] = 1; for (int i = 3 ; i<base ; i++){ po2[i] = po2[i-1]+i-1; } for (int i = 4 ; i<base ; i++){ po3[i] = po3[i-1]+po2[i-1]; } int t = 1; cin >> t; rep(t) solve(i); } |
English