#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "lib/debug.h"
#else
#define debug(...) 228
#endif
#define pb push_back
typedef long long ll;
typedef long double ld;
int tst;
int n;
const int maxN = 2e5 + 10;
ll a[maxN];
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
ll L = 0;
ll R = 300 * n;
while (R - L > 1) {
ll mid = (L + R) / 2;
ll left = 0;
bool ok = true;
for (int i = 1; i <= n; i++) {
ll le = -1;
ll ri = min(300LL, mid - left + 1);
while (ri - le > 1) {
ll cnt = (ri + le) / 2;
ll score = (cnt * (cnt - 1) * (cnt - 2)) / 6;
score += (cnt * (cnt - 1)) / 2 * (mid - cnt);
score += cnt * left * (mid - left - cnt);
// debug(score, le, ri, mid, left, cnt);
if (score >= a[i]) ri = cnt;
else le = cnt;
}
// debug(le, ri, mid, left);
if (ri == mid - left + 1) {
ok = false;
break;
}
left += ri;
}
if (!ok) L = mid;
else {
R = mid;
}
}
cout << R << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
auto start = std::chrono::high_resolution_clock::now();
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
cin >> tst;
while (tst--) solve();
auto end = std::chrono::high_resolution_clock::now();
std::cerr << "Execution Time: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
<< " ms" << std::endl;
return 0;
}
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 69 70 71 72 73 | #ifdef DEBUG #define _GLIBCXX_DEBUG #endif //#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; #ifdef DEBUG #include "lib/debug.h" #else #define debug(...) 228 #endif #define pb push_back typedef long long ll; typedef long double ld; int tst; int n; const int maxN = 2e5 + 10; ll a[maxN]; void solve() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } ll L = 0; ll R = 300 * n; while (R - L > 1) { ll mid = (L + R) / 2; ll left = 0; bool ok = true; for (int i = 1; i <= n; i++) { ll le = -1; ll ri = min(300LL, mid - left + 1); while (ri - le > 1) { ll cnt = (ri + le) / 2; ll score = (cnt * (cnt - 1) * (cnt - 2)) / 6; score += (cnt * (cnt - 1)) / 2 * (mid - cnt); score += cnt * left * (mid - left - cnt); // debug(score, le, ri, mid, left, cnt); if (score >= a[i]) ri = cnt; else le = cnt; } // debug(le, ri, mid, left); if (ri == mid - left + 1) { ok = false; break; } left += ri; } if (!ok) L = mid; else { R = mid; } } cout << R << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); auto start = std::chrono::high_resolution_clock::now(); #ifdef DEBUG freopen("input.txt", "r", stdin); #endif cin >> tst; while (tst--) solve(); auto end = std::chrono::high_resolution_clock::now(); std::cerr << "Execution Time: " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << " ms" << std::endl; return 0; } |
English