#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pib = pair<int,bool>;
using ll = long long;
using ld = long double;
#define all(x) (x).begin(),(x).end()
#ifdef fread_unlocked
#define fread fread_unlocked
#define fwrite fwrite_unlocked
#endif
#define lc ind<<1
#define rc ind<<1|1
const int MN = 501265, MOD = 1e9+7, BASE = 31;
int h[MN], mx[MN], sq[MN];
int get (int x, int y) {
return h[y] + sq[abs(x-y)];
}
int intersect (int a, int b) { //when does a pass b?
int low = 1, high = min(a,b) - 1, mid, ans = 0;
while (low <= high) {
mid = (low + high) / 2;
if (get(mid,a) > get(mid,b)) low = (ans = mid) + 1;
else high = mid - 1;
}
return ans;
}
int main () {
for (int i = 1; i <= 708; i++) sq[i*i]=i;
for (int i = 501263; i >= 1; i--) if (!sq[i]) sq[i] = sq[i+1];
int n;
scanf ("%d",&n);
for (int i = 1; i <= n; i++) scanf ("%d",h+i);
deque<int> dq;
for (int i = n; i >= 1; i--) {
while ((int)dq.size()>1 && get(i,dq.front()) < get(i,dq[1])) dq.pop_front();
if (i<n) mx[i] = max(mx[i],get(i,dq.front()));
while ((int)dq.size() > 1 && intersect(i,dq.back()) > intersect(dq.back(),dq[(int)dq.size()-2])) dq.pop_back();
dq.push_back(i);
}
dq.clear();
reverse(h+1,h+1+n);
for (int i = n; i >= 1; i--) {
while ((int)dq.size()>1 && get(i,dq.front()) < get(i,dq[1])) dq.pop_front();
if (i<n) mx[n-i+1] = max(mx[n-i+1],get(i,dq.front()));
while ((int)dq.size() > 1 && intersect(i,dq.back()) > intersect(dq.back(),dq[(int)dq.size()-2])) dq.pop_back();
dq.push_back(i);
}
for (int i = 1; i <= n; i++) printf ("%d\n",mx[i] - h[n-i+1]);
return 0;
}
Compilation message
pio.cpp: In function 'int main()':
pio.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d",&n);
~~~~~~^~~~~~~~~
pio.cpp:33:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int i = 1; i <= n; i++) scanf ("%d",h+i);
~~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
3192 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
3704 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
3760 KB |
Output is correct |
2 |
Correct |
34 ms |
3576 KB |
Output is correct |
3 |
Incorrect |
53 ms |
3704 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
4472 KB |
Output is correct |
2 |
Correct |
75 ms |
4600 KB |
Output is correct |
3 |
Incorrect |
75 ms |
4600 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
178 ms |
7460 KB |
Output is correct |
2 |
Correct |
166 ms |
7224 KB |
Output is correct |
3 |
Incorrect |
174 ms |
7164 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
285 ms |
11896 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
410 ms |
16096 KB |
Output is correct |
2 |
Correct |
361 ms |
13512 KB |
Output is correct |
3 |
Incorrect |
391 ms |
14200 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
402 ms |
13568 KB |
Output is correct |
2 |
Correct |
361 ms |
13508 KB |
Output is correct |
3 |
Incorrect |
389 ms |
14072 KB |
Output isn't correct |