// Make the best become better
// No room for laziness
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 5e5 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n;
int a[maxN];
int f[21][maxN];
int lg[maxN];
void SparseTable()
{
for(int i=1; i<=n; i++)
f[0][i] = a[i];
for(int k=1; k<=lg[n]; k++)
for(int i=1; i<=n; i++)
{
int j = i + (1 << (k - 1));
if(j > n) f[k][i] = f[k - 1][i];
else f[k][i] = max(f[k - 1][i], f[k - 1][j]);
}
}
inline int get(int l, int r)
{
int k = lg[r - l + 1];
return max(f[k][l], f[k][r - (1 << k) + 1]);
}
void ReadInput()
{
cin >> n;
for(int i=1; i<=n; i++)
cin >> a[i];
for(int i=2; i<maxN; i++)
lg[i] = lg[i / 2] + 1;
}
void Solve()
{
SparseTable();
for(int i=1; i<=n; i++)
{
int res = 0;
int len = (int)sqrt(i - 2) + 1;
while(len >= 1)
{
int r = i - (len - 1) * (len - 1) - 1;
int l = i - len * len;
l = max(1, l);
if(a[i] + res - len >= get(l, i - 1)) break;
res = max(res, get(l, r) + len - a[i]);
len--;
if(n > 2e5 && len == 300) len = 200;
}
len = (int)sqrt(n - i - 1) + 1;
while(len >= 1)
{
int l = i + (len - 1) * (len - 1) + 1;
int r = i + len * len;
r = min(r, n);
if(a[i] + res - len >= get(i + 1, r)) break;
res = max(res, get(l, r) + len - a[i]);
len--;
if(n > 2e5 && len == 300) len = 200;
}
cout << res << '\n';
}
}
int32_t main()
{
//freopen("sol.inp", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ReadInput();
Solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
4556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
6176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
6996 KB |
Output is correct |
2 |
Correct |
17 ms |
6936 KB |
Output is correct |
3 |
Correct |
99 ms |
7168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
9756 KB |
Output is correct |
2 |
Correct |
26 ms |
9684 KB |
Output is correct |
3 |
Correct |
178 ms |
10348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
20380 KB |
Output is correct |
2 |
Correct |
52 ms |
20268 KB |
Output is correct |
3 |
Incorrect |
383 ms |
20960 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
657 ms |
33340 KB |
Output is correct |
2 |
Correct |
85 ms |
31244 KB |
Output is correct |
3 |
Incorrect |
861 ms |
33376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
926 ms |
46272 KB |
Output is correct |
2 |
Correct |
122 ms |
43664 KB |
Output is correct |
3 |
Execution timed out |
1079 ms |
44224 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
43916 KB |
Output is correct |
2 |
Correct |
117 ms |
43412 KB |
Output is correct |
3 |
Execution timed out |
1078 ms |
43952 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |