#include <iostream>
#include <algorithm>
using namespace std;
int N, A[1 << 19], dp[1 << 19][22], ret[1 << 19], dp2[1 << 19][22];
int main() {
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> A[i];
if (A[i] > 0) { for (int j = 0; j <= 21; j++) { dp[i][j] = i; dp2[i][j] = 0; } ret[i] = A[i]; }
else {
int cx = i - 1, level = -A[i];
for (int j = 21; j >= 0; j--) {
if (dp2[cx][j] >= level) cx = dp[cx][j];
}
cx--;
if (cx == 0) { ret[i] = 0; for (int j = 0; j <= 21; j++) dp2[i][j] = level; }
else {
ret[i] = A[cx];
dp[i][0] = cx - 1; dp2[i][0] = level;
for (int j = 1; j <= 21; j++) {
dp[i][j] = dp[dp[i][j - 1]][j - 1];
dp2[i][j] = min(dp2[i][j - 1], dp2[dp[i][j]][j - 1]);
}
}
}
}
for (int i = 1; i <= N; i++) cout << ret[i] << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
526 ms |
56696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
269 ms |
29048 KB |
Integer -89532 violates the range [0, 150000] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |