#include <bits/stdc++.h>
using namespace std;
const int maxn = 1<<19;
int n, a[maxn], b[maxn];
int dq[maxn];
int y, z;
void xfill(int s, int e, int l, int r) {
if (s>e) return;
int m = (s+e)/2, k = max(m, l);
y = 0, z = 0;
for (int i=k-m+1; i<=k; i++) {
while (y<z and a[dq[z-1]] < a[i]) z--;
dq[z++] = i;
}
while (k+1<=r) {
if (a[k+1] > a[dq[y]]) break;
k++;
if (dq[y] < k-m+1) y++;
while (y<z and a[dq[z-1]] < a[k]) z--;
dq[z++] = k;
}
if (k>r) k = r;
b[m] = k;
if (s<e) {
xfill(s, m-1, l, k);
xfill(m+1, e, k, r);
}
}
int main() {
cin >> n;
for (int i=1; i<=n; i++) scanf("%d", &a[i]);
xfill(1, n, 1, n);
for (int i=1; i<=n; i++) {
if (b[i] == n) printf("-1 ");
else printf("%d ", b[i] - i + 1);
}
}
Compilation message
box.cpp: In function 'int main()':
box.cpp:37:32: 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", &a[i]);
~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
6 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
500 KB |
Output is correct |
4 |
Correct |
4 ms |
500 KB |
Output is correct |
5 |
Correct |
3 ms |
500 KB |
Output is correct |
6 |
Correct |
3 ms |
500 KB |
Output is correct |
7 |
Correct |
3 ms |
520 KB |
Output is correct |
8 |
Correct |
3 ms |
520 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
6 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
500 KB |
Output is correct |
4 |
Correct |
4 ms |
500 KB |
Output is correct |
5 |
Correct |
3 ms |
500 KB |
Output is correct |
6 |
Correct |
3 ms |
500 KB |
Output is correct |
7 |
Correct |
3 ms |
520 KB |
Output is correct |
8 |
Correct |
3 ms |
520 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
6 ms |
596 KB |
Output is correct |
13 |
Correct |
49 ms |
596 KB |
Output is correct |
14 |
Execution timed out |
1064 ms |
1096 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |