# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
72168 | 유애나 (#118) | 박스런 (FXCUP3_box) | C++17 | 482 ms | 48600 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |