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 v[300005];
int jump[20][300005];
int Find(int k,int lv){
if(-v[k]<=lv)return k;
for(int j=19;j>=0;j--){
if(-v[jump[j][k]]>lv){
k=jump[j][k];
}
}
return jump[0][k];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
for(int i=1;i<=n;i++){
cin>>v[i];
if(v[i]<0){
int tmp=Find(i-1,-v[i]-1)-1;
int pa=Find(tmp,-v[i]-1);
jump[0][i]=pa;
for(int j=1;j<20;j++){
jump[j][i]=jump[j-1][jump[j-1][i]];
}
}
cout<<v[Find(i,0)]<<'\n';
}
return 0;
}
# | 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... |