This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
#include<bits/stdc++.h>
/**/
//typedef int ll;
typedef long long ll;
typedef unsigned long long ull;
typedef std::string str;
//typedef vector<std::vector<ll>> vv;
/*typedef __int128 vll;
typedef unsigned __int128 uvll;*/
#define llll std::pair<ll , ll>
#define pb push_back
#define pf push_front
#define halo cout << "hello\n"
#define fi first
#define sec second
#define vv(x) std::vector<std::vector<x>>
#define all(a) a.begin() , a.end()
const ll limit = 1e9+7;
const ll ous = 5e5 + 7;
const ll dx[4] = {-1 , 0 , 1 , 0} , dy[4] = {0,1,0,-1};
ll n , m;std::vector<ll> ar;
struct psegt{
psegt *l=NULL , *r=NULL;
ll mx = 0;
};
psegt* build(ll l , ll r){
psegt *o = new psegt;
if(l == r){
return o;
}
ll md = (l + r)/2;
o->l = build(l , md);
o->r = build(md+1,r);
o->mx = std::max(o->l->mx , o->r->mx);
return o;
}
psegt* add(ll val , ll ind , psegt *cur , ll l , ll r){
psegt *o = new psegt;
if(l == r){
o->l = NULL;o->r = NULL;
o->mx = val;
return o;
}
o->l = cur->l;
o->r = cur->r;
ll md =(l + r)/2;
if(md >= ind){
o->l = add(val , ind , cur->l , l , md);
}
else{
o->r = add(val , ind , cur->r , md+1,r);
}
o->mx = std::max(o->l->mx , o->r->mx);
return o;
}
ll fnd(ll l , ll r , psegt *cur , ll nt){
ll md = (l + r) / 2;
//std::cout << l << " " << r << " " << nt << std::endl;
if(l == r){
return cur->mx;
}
if(md > nt){
return fnd(l , md , cur->l , nt);
}
else if(md == nt){
return cur->l->mx;
}
else if(r == nt){
return cur->mx;
}
else{
ll o = std::max(cur->l->mx , fnd(md , r , cur->r , nt));
return o;
}
}
void solve(){
std::vector<psegt*> v(1);
std::vector<ll> lsans(1 , 0);
ll n;std::cin >> n;
v[0] = build(0 , n);
for(ll i =1;n>=i;i++){
ll x;std::cin >> x;
if(x > 0){
v.resize(v.size() + 1);
v[v.size() - 1] = add(i , 0 , v[(ll)v.size() - 2] , 0 , n);
lsans.pb(x);
}
else{
v.resize(v.size() + 1);
ll undo = fnd(0 , n , v[(ll)v.size() - 2] , -x-1) - 1;
lsans.pb(lsans[undo]);
v[v.size() - 1] = add(i , -x , v[undo] , 0 , n);
//std::cout << "-----------" << undo << " " << i << std::endl;
}
}
for(ll i =1;n>=i;i++){
std::cout << lsans[i] << "\n";
}
return;/**/
}
signed main(){
std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
ll t=1;
//std::cin >> t;
ll o = 1;
while(t--){
//cout << "Case " << o++ << ":\n";
solve();
}
return 0;
}/**/
Compilation message (stderr)
edi.cpp:5:78: warning: "/*" within comment [-Wcomment]
5 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
|
edi.cpp: In function 'int main()':
edi.cpp:111:8: warning: unused variable 'o' [-Wunused-variable]
111 | ll o = 1;
| ^
# | 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... |