#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",max(0,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);
~~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
2808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
3192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
3128 KB |
Output is correct |
2 |
Correct |
33 ms |
3456 KB |
Output is correct |
3 |
Incorrect |
50 ms |
3576 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
3580 KB |
Output is correct |
2 |
Correct |
76 ms |
3960 KB |
Output is correct |
3 |
Incorrect |
75 ms |
4344 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
178 ms |
5188 KB |
Output is correct |
2 |
Correct |
168 ms |
5496 KB |
Output is correct |
3 |
Incorrect |
172 ms |
6008 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
279 ms |
8568 KB |
Output is correct |
2 |
Correct |
256 ms |
10360 KB |
Output is correct |
3 |
Incorrect |
269 ms |
10616 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
403 ms |
11144 KB |
Output is correct |
2 |
Correct |
378 ms |
8972 KB |
Output is correct |
3 |
Incorrect |
391 ms |
11512 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
401 ms |
8696 KB |
Output is correct |
2 |
Correct |
366 ms |
8912 KB |
Output is correct |
3 |
Incorrect |
381 ms |
11512 KB |
Output isn't correct |