# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134763 | Ace | Editor (BOI15_edi) | C++14 | 272 ms | 57308 KiB |
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;
const int N = 3e5;
int n;
int ans[N+5];
int mini[N+5][22];
int par[N+5][22];
void make_spar(int x){
for(int j=1;j<=20;j++){
par[x][j] = par[par[x][j-1]][j-1];
mini[x][j] = min(mini[x][j-1],mini[par[x][j-1]][j-1]);
}
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
int x;
scanf("%d",&x);
if(x>0){
ans[i] = x;
par[i][0] = i;
continue;
}
x*=-1;
int cur = i-1;
for(int j=20;j>=0;j--){
if(mini[cur][j] < x){ //valid
continue;
}
cur = par[cur][j];
}
par[i][0] = cur-1;
ans[i] = ans[par[i][0]];
mini[i][0] = x;
make_spar(i);
}
for(int i=1;i<=n;i++){
printf("%d\n",ans[i]);
}
return 0;
}
Compilation message (stderr)
# | 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... |