#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T>
bool chmax(T &val, T nv) {
return val < nv ? (val = nv, true) : false;
}
template<class T>
bool chmin(T &val, T nv) {
return nv < val ? (val = nv, true) : false;
}
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void debug(auto L, auto R) { while (L < R) cerr << *L << " \n"[L+1==R], ++L; }
void kout(){ cerr << endl; }
template<class T1, class ...T2> void kout(T1 a, T2 ...e) { cerr << a << ' ', kout(e...); }
#else
#define DE(...) 0
#define debug(...) 0
#endif
// What I should check
// 1. overflow
// 2. corner cases
// Enjoy the problem instead of hurrying to AC
// Good luck !
const int MAX_N = 300010, MAX_K = 19;
int n, state[MAX_N], par[MAX_N][MAX_K], lev[MAX_N];
int getpa(int x, int mxlev) {
if (lev[x] <= mxlev) return x;
for (int i = MAX_K - 1;i >= 0;--i)
if (lev[ par[x][i] ] > mxlev) x = par[x][i];
return par[x][0];
}
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n;
for (int i = 1;i <= n;++i) cin >> state[i];
for (int i = 1;i <= n;++i) {
if (state[i] < 0) {
lev[i] = -state[i];
int z = getpa(i - 1, lev[i] - 1);
par[i][0] = getpa(z - 1, lev[i] - 1);
for (int j = 1;j < MAX_K;++j)
par[i][j] = par[i-1][ par[i-1][j] ];
}
cout << state[ getpa(i, 0) ] << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Integer -5 violates the range [0, 30] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
125 ms |
28396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
59 ms |
8684 KB |
Integer -23782 violates the range [0, 150000] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Integer -5 violates the range [0, 30] |
2 |
Halted |
0 ms |
0 KB |
- |