# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
72168 | 유애나 (#118) | Box Run (FXCUP3_box) | C++17 | 482 ms | 48600 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int n, h[N], lg[N], d[N][20], nx[N];
int g(int s, int e){
e = min(e, n + 1);
int l = lg[e - s + 1];
int x = d[s][l], y = d[e - (1 << l) + 1][l];
return (h[x] > h[y] || (h[x] == h[y] && x < y)) ? x : y;
}
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d", h + i);
h[n + 1] = int(2e9);
for(int i = 1, j = 0; i <= n + 1; i++){
while((2 << j) < i) j++;
lg[i] = j;
d[i][0] = i;
}
for(int i = 1; i < 20; i++){
for(int j = 1; j <= n + 1; j++){
int x = d[j][i - 1], y = d[min(n + 1, j + (1 << (i - 1)))][i - 1];
if(h[x] > h[y] || (h[x] == h[y] && x < y)) d[j][i] = x;
else d[j][i] = y;
}
}
for(int i = 1; i <= n; i++){
nx[i] = i;
for(int j = 19; j >= 0; j--){
if(h[d[nx[i]][j]] <= h[i]) nx[i] += (1 << j);
}
}
for(int i = 1; i <= n; i++){
int t = g(1, i);
while(t < n){
int nt = nx[t];
if(nt <= min(n, t + i)){
t = nt - i;
break;
}
else t = g(t + 1, t + i);
}
printf("%d ", t >= n ? -1 : t);
}
puts("");
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |