# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1090785 | PieArmy | Editor (BOI15_edi) | C++17 | 64 ms | 28500 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;}
const int LO=19;
int n;
int arr[300001],dep[300001];
int par[300001][LO];
void code(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>arr[i];
}
set<pair<int,int>>st;st.insert({0,0});
for(int i=1;i<=n;i++){
if(arr[i]>0){
st.insert({-i,arr[i]});
}
else{
if(arr[i]==-1){
par[i][0]=-st.begin()->fr;
for(int j=1;j<LO;j++){
par[i][j]=par[par[i][j-1]][j-1];
}
}
else{
int root=i-1;
if(arr[root]>arr[i])root=i-1;
else{
for(int j=LO-1;j>=1;j--){
if(par[root][j]==0)continue;
if(arr[par[root][j]]>arr[i])continue;
root=par[root][j];
}
root=par[root][1];
}
par[i][0]=root;
for(int j=1;j<LO;j++){
par[i][j]=par[par[i][j-1]][j-1];
}
}
dep[i]=dep[par[i][0]]+1;
int root=i;
for(int j=0;j<LO;j++){
if(dep[i]&pie(j)){
root=par[root][j];
}
}
if(dep[i]&1)st.erase({-root,arr[root]});
else st.insert({-root,arr[root]});
}
cout<<st.begin()->sc<<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... |