Submission #667619

#TimeUsernameProblemLanguageResultExecution timeMemory
667619ktkeremEditor (BOI15_edi)C++17
100 / 100
489 ms215172 KiB
/*#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; //std::cout << val << "\n"; 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 << " " << cur->mx << 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{ ll o = std::max(cur->l->mx , fnd(md +1, 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.pb(add(i , 0 , v[(ll)v.size() - 1] , 0 , n)); lsans.pb(x); } else{ x = -x; ll undo = fnd(0 , n , v[(ll)v.size() - 1] , x-1) - 1; undo = std::max(undo , 0ll); lsans.pb(lsans[undo]); v.pb(add(i , x , v[undo] , 0 , n)); //std::cout << "-----------" << x << " " << 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:109:8: warning: unused variable 'o' [-Wunused-variable]
  109 |     ll o = 1;
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...