# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1091091 | PieArmy | Editor (BOI15_edi) | C++17 | 124 ms | 28004 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.
typedef long long ll;
ll pie(ll army){return (1ll<<army);}
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define endl '\n'
#define mid ((left+right)>>1)
const ll inf=2000000000000000005;
const int sonsuz=2000000005;
using namespace std;
ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;}
int n;
int arr[300001];
int par[300001][19];
void code(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>arr[i];
if(arr[i]<0){
int root=i-1;
if(arr[root]<=arr[i]){
for(int j=19-1;j>=0;j--){
if(arr[par[root][j]]<=arr[i]){
root=par[root][j];
}
}
root=par[root][0];
}
root--;
if(arr[root]<=arr[i]){
for(int j=19-1;j>=0;j--){
if(arr[par[root][j]]<=arr[i]){
root=par[root][j];
}
}
root=par[root][0];
}
par[i][0]=root;
for(int j=1;j<19;j++){
par[i][j]=par[par[i][j-1]][j-1];
}
root=i;
for(int j=19-1;j>=0;j--){
if(arr[par[root][j]]<0){
root=par[root][j];
}
}
root=par[root][0];
cout<<arr[root]<<endl;
}
else{
cout<<arr[i]<<endl;
}
}
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
int t=1;
if(!t)cin>>t;
while(t--){code();cout<<endl;}
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... |