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>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
int main(){
AquA;
int n;
cin >> n;
vector<vector<int> > as(21,vector<int>(n));
vector<int> lv,az;
auto get=[&](int x,int a){
if(x<0){
return -1;
}
if(lv[x]<a){
return x;
}
for(int j=20;j>=0;j--){
if(lv[as[j][x]]>=a){
x=as[j][x];
}
}
x=as[0][x];
return x;
};
int ans=0;
for(int i=0;i<n;i++){
int a;
cin >> a;
if(a<0){
a=-a;
lv.push_back(a);
int x=get(i-1,a);
//cout << x << endl;
int y=get(x-1,a);
if(y>=0){
as[0][i]=y;
ans=az[as[20][y]];
}
else{
as[0][i]=i;
ans=0;
}
}
else{
lv.push_back(0);
as[0][i]=i;
ans=a;
}
az.push_back(ans);
cout << ans << "\n";
for(int j=1;j<21;j++){
as[j][i]=as[j-1][as[j-1][i]];
}
}
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... |