#include <bits/stdc++.h>
using namespace std;
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
const int inf = 2e9;
const int N = 1e6 + 15;
int n, a[N], k, f[N];
pii t[N << 4];
void build(int v, int tl, int tr, int keep = -1) {
if(tl == tr) {
t[v] = {a[tl], keep * tl};
return;
}
int mid = tl + tr >> 1;
build(v << 1, tl, mid, keep);
build(v << 1 | 1, mid + 1, tr, keep);
t[v] = max(t[v << 1], t[v << 1 | 1]);
}
pii get(int v, int tl, int tr, int l, int r) {
if(tl > r || tr < l)
return {-inf, -inf};
if(tl >= l && tr <= r)
return t[v];
int mid = tl + tr >> 1;
return max(get(v << 1, tl, mid, l, r), get(v << 1 | 1, mid + 1, tr, l, r));
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
build(1, 1, n);
for(int i = 2; i <= n; ++i) {
pii now = get(1, 1, n, 1, i - 1);
int hj = now.f, sqr = ceil(sqrt(i + now.se));
f[i] = hj + sqr - a[i];
}
build(1, 1, n, 1);
for(int i = n - 1; i; --i) {
pii now = get(1, 1, n, i + 1, n);
int hj = now.f, sqr = ceil(sqrt(now.se - i));
f[i] = max(f[i], hj + sqr - a[i]);
}
for(int i = 1; i <= n; ++i)
cout << f[i] << endl;
return 0;
}
Compilation message
pio.cpp: In function 'void build(int, int, int, int)':
pio.cpp:30:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = tl + tr >> 1;
~~~^~~~
pio.cpp: In function 'std::pair<int, int> get(int, int, int, int, int)':
pio.cpp:41:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = tl + tr >> 1;
~~~^~~~
pio.cpp: In function 'int main()':
pio.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
pio.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
380 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
99 ms |
1692 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
162 ms |
2680 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
221 ms |
2856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
326 ms |
4780 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
741 ms |
9652 KB |
Output is correct |
2 |
Correct |
744 ms |
9252 KB |
Output is correct |
3 |
Incorrect |
745 ms |
9136 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1069 ms |
17856 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1068 ms |
19916 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1047 ms |
18924 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |