-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path2074.cpp
61 lines (51 loc) · 1.46 KB
/
2074.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* @file 2074.cpp
* @author Macesuted ([email protected])
* @date 2022-05-30
*
* @copyright Copyright (c) 2022
*
*/
#include <bits/stdc++.h>
using namespace std;
bool mem1;
#define maxn 100005
#define maxlgn 20
int a[maxn], maxVal[maxlgn][maxn], lg[maxn];
int getMax(int l, int r) {
int x = lg[r - l + 1];
return max(maxVal[x][l], maxVal[x][r - (1 << x) + 1]);
}
void solve(void) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i], maxVal[0][i] = a[i];
for (int i = 1; i <= n; i++) {
lg[i] = lg[i - 1];
if (1 << (lg[i] + 1) <= i) lg[i]++;
}
for (int i = 1; i < maxlgn; i++)
for (int j = 1; j <= n; j++) maxVal[i][j] = max(maxVal[i - 1][j], maxVal[i - 1][min(n, j + (1 << (i - 1)))]);
for (int i = 1; i <= n; i++) {
int ans = 0;
for (int v = 1; i - (v - 1) * (v - 1) - 1 >= 1; v++)
ans = max(ans, getMax(max(1, i - v * v), i - (v - 1) * (v - 1) - 1) + v);
for (int v = 1; i + (v - 1) * (v - 1) + 1 <= n; v++)
ans = max(ans, getMax(i + (v - 1) * (v - 1) + 1, min(n, i + v * v)) + v);
cout << max(0, ans - a[i]) << endl;
}
return;
}
bool mem2;
int main() {
ios::sync_with_stdio(false);
#ifdef LOCAL
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
#endif
int _ = 1;
while (_--) solve();
#ifdef LOCAL
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
#endif
return 0;
}