#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 endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
struct point {
int i, l, r;
};
const int N = 5e5 + 15;
int n, a[N], dp[N];
deque <point> q;
inline double get(int j, int i) {
return a[i] + sqrt(abs(i - j));
}
void process() {
q.clear();
for(int i = 1; i <= n; ++i) {
if(!q.empty())
++q.front().l;
while(!q.empty() && q.front().r < q.front().l)
q.pop_front();
while(!q.empty() && get(q.back().l, q.back().i) <= get(q.back().l, i))
q.pop_front();
if(q.empty())
q.push_back({i, i, n});
else {
int l = q.back().l, r = q.back().r, res = 0;
while(l <= r) {
int mid = l + r >> 1;
if(get(mid, i) >= get(mid, q.back().i))
res = mid, r = mid - 1;
else
l = mid + 1;
}
if(res) {
if(res - 1 >= q.back().l)
q.back().r = res - 1;
else
q.pop_back();
q.push_back({i, res, n});
}
}
dp[i] = max(dp[i], (int)ceil(get(i, q.front().i)) - a[i]);
}
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
process();
reverse(a + 1, a + 1 + n);
reverse(dp + 1, dp + 1 + n);
process();
for(int i = n; i; --i)
printf("%d\n", dp[i]);
return 0;
}
Compilation message
pio.cpp: In function 'void process()':
pio.cpp:47:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
pio.cpp: In function 'int main()':
pio.cpp:67:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
pio.cpp:69:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
1144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
1188 KB |
Output is correct |
2 |
Correct |
34 ms |
1276 KB |
Output is correct |
3 |
Incorrect |
38 ms |
1372 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
1500 KB |
Output is correct |
2 |
Correct |
56 ms |
1528 KB |
Output is correct |
3 |
Incorrect |
57 ms |
2040 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
137 ms |
3192 KB |
Output is correct |
2 |
Correct |
128 ms |
3048 KB |
Output is correct |
3 |
Incorrect |
135 ms |
3724 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
228 ms |
6584 KB |
Output is correct |
2 |
Correct |
206 ms |
4600 KB |
Output is correct |
3 |
Incorrect |
212 ms |
6544 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
329 ms |
9248 KB |
Output is correct |
2 |
Correct |
300 ms |
6264 KB |
Output is correct |
3 |
Incorrect |
305 ms |
9336 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
310 ms |
6776 KB |
Output is correct |
2 |
Correct |
296 ms |
6296 KB |
Output is correct |
3 |
Incorrect |
305 ms |
9208 KB |
Output isn't correct |