// Make the best become better
// No room for laziness
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#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--;
}
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--;
}
cout << res << '\n';
}
}
int32_t main()
{
//freopen("sol.inp", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ReadInput();
Solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
4560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
6164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
6996 KB |
Output is correct |
2 |
Correct |
13 ms |
6888 KB |
Output is correct |
3 |
Correct |
96 ms |
7236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
9700 KB |
Output is correct |
2 |
Correct |
24 ms |
9676 KB |
Output is correct |
3 |
Correct |
169 ms |
10276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
20416 KB |
Output is correct |
2 |
Correct |
57 ms |
20284 KB |
Output is correct |
3 |
Correct |
547 ms |
21068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
842 ms |
33260 KB |
Output is correct |
2 |
Correct |
80 ms |
31216 KB |
Output is correct |
3 |
Execution timed out |
1074 ms |
32544 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1067 ms |
45936 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
43912 KB |
Output is correct |
2 |
Correct |
143 ms |
43404 KB |
Output is correct |
3 |
Execution timed out |
1077 ms |
43048 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |