# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
73175 |
2018-08-28T02:54:01 Z |
test |
Box Run (FXCUP3_box) |
C++14 |
|
260 ms |
36780 KB |
#include<bits/stdc++.h>
using namespace std;
const int MN = 500010;
int N;
int H[MN];
struct BIT {
vector<int> tree;
void init() {
tree = vector<int>(4 * N, 0);
}
void upd(int idx, int val, int l, int r, int n) {
if(idx < l || r < idx) return;
if(l == r) {
tree[n] = val;
return;
}
int m = (l + r)>>1;
upd(idx, val, l, m, 2*n);
upd(idx, val, m + 1, r, 2*n + 1);
tree[n] = max(tree[2*n], tree[2*n + 1]);
}
int kquer(int k, int l, int r, int n) {
if(tree[n] < k) return -1;
if(l == r) return l;
int m = (l + r)>>1;
if(tree[2*n + 1] < k) return kquer(k, l, m, 2*n);
else return kquer(k, m + 1, r, 2*n + 1);
}
} bit;
int mn[MN];
int main() {
scanf("%d", &N);
for(int i = 0; i < N; i++) {
scanf("%d", &H[i]);
}
for(int i = 0; i <= N; i++) mn[i] = 1e9;
bit.init();
for(int i = 0; i < N; i++) {
int a = bit.kquer(H[i], 0, N - 1, 1);
bit.upd(i, H[i], 0, N - 1, 1);
if(mn[i - a - 1] == 1e9) mn[i - a - 1] = i;
}
for(int i = N; i >= 0; i--) {
mn[i - 1] = min(mn[i - 1], mn[i]);
}
for(int i = 1; i <= N; i++) {
if(mn[i] == 1e9) printf("-1 ");
else printf("%d ", mn[i] - i + 1);
}
}
Compilation message
box.cpp: In function 'int main()':
box.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
~~~~~^~~~~~~~~~
box.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &H[i]);
~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
352 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
400 KB |
Output is correct |
4 |
Correct |
3 ms |
404 KB |
Output is correct |
5 |
Correct |
2 ms |
516 KB |
Output is correct |
6 |
Correct |
2 ms |
520 KB |
Output is correct |
7 |
Correct |
3 ms |
524 KB |
Output is correct |
8 |
Correct |
3 ms |
528 KB |
Output is correct |
9 |
Correct |
3 ms |
640 KB |
Output is correct |
10 |
Correct |
3 ms |
644 KB |
Output is correct |
11 |
Correct |
2 ms |
696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
352 KB |
Output is correct |
2 |
Correct |
2 ms |
360 KB |
Output is correct |
3 |
Correct |
2 ms |
400 KB |
Output is correct |
4 |
Correct |
3 ms |
404 KB |
Output is correct |
5 |
Correct |
2 ms |
516 KB |
Output is correct |
6 |
Correct |
2 ms |
520 KB |
Output is correct |
7 |
Correct |
3 ms |
524 KB |
Output is correct |
8 |
Correct |
3 ms |
528 KB |
Output is correct |
9 |
Correct |
3 ms |
640 KB |
Output is correct |
10 |
Correct |
3 ms |
644 KB |
Output is correct |
11 |
Correct |
2 ms |
696 KB |
Output is correct |
12 |
Correct |
3 ms |
700 KB |
Output is correct |
13 |
Correct |
5 ms |
844 KB |
Output is correct |
14 |
Correct |
23 ms |
2428 KB |
Output is correct |
15 |
Correct |
38 ms |
4048 KB |
Output is correct |
16 |
Correct |
61 ms |
5660 KB |
Output is correct |
17 |
Correct |
139 ms |
12764 KB |
Output is correct |
18 |
Correct |
206 ms |
18868 KB |
Output is correct |
19 |
Correct |
209 ms |
25896 KB |
Output is correct |
20 |
Correct |
242 ms |
32612 KB |
Output is correct |
21 |
Correct |
260 ms |
36780 KB |
Output is correct |