Submission #1130797

#TimeUsernameProblemLanguageResultExecution timeMemory
1130797idiotcomputerEditor (BOI15_edi)C++20
100 / 100
103 ms28232 KiB
#include <bits/stdc++.h> using namespace std; const int mxN = 3e5+5; int p[mxN][20]; int l[mxN]; int v[mxN]; int getp(int i, int t){ //first parent of i with level < t while (l[i] >= t){ for (int j = 1; j < 20; j++){ if (l[p[i][j]] < t){ i = p[i][j-1]; break;} } } return i; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; l[0] = -1; memset(p,0,sizeof(p)); int c; for (int i = 1; i <= n; i++){ cin >> c; if (c > 0){ l[i] = 0; v[i] = c; cout << c << '\n'; } else { c=-c; l[i] = c; int idx = getp(i-1,c); idx = getp(idx-1,c); for (int j = 0; idx > 0, j < 20; j++){ p[i][j] = idx; idx = p[idx][j]; } cout << v[getp(i,1)] << '\n'; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...