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;
int vl[300100],bj[300100][20],lev[300100];
int go(int x,int t){
if(lev[x]<t)return x;
for(int i=20;i--;)
if(lev[bj[x][i]]>=t)
x=bj[x][i];
return bj[x][0];
}
int main(){
cin.tie(0)->sync_with_stdio(0);
int n;
cin>>n;
for(int i=1;i<=n;i++){
int x;
cin>>x;
if(x<0){
lev[i]=-x;
bj[i][0]=go(go(i-1,lev[i])-1,lev[i]);
for(int j=1;j<20;j++)
bj[i][j]=bj[bj[i][j-1]][j-1];
}else vl[i]=x;
cout<<vl[go(i,1)]<<'\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |