Submission #1276263

#TimeUsernameProblemLanguageResultExecution timeMemory
1276263ThylOneEditor (BOI15_edi)C++20
35 / 100
3095 ms6360 KiB
//####################
//Editor
//####################
#include<bits/stdc++.h> 


#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define eb emplace_back
 
using namespace std;

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	
	vector<bool> on(n+1, false);
	on[0] = true;
	vector<pair<int,int>> opps;
	opps.pb({0,0});
	for(int i = 0 ; i < n  ; i++){
		int opp;cin>>opp;
		on[i+1] = true;
		if(opp > 0){
			opps.pb({0,-opp});
		}else{
			int to_undo = -1;
			for(int j = opps.size()-1 ; j>=0 ; j--){
				if(on[j] && opps[j].first < -opp){to_undo=j;break;}
			}
			opps.pb({-opp, to_undo});
			int act = to_undo;
			while(opps[act].second > 0){
				on[act] = !on[act];
				act = opps[act].second;
			}
			if(act !=0){
				on[act] = !on[act];
			}
		}
		for(int j = opps.size()-1;j>=0;j--){
			if(on[j] && opps[j].first==0){
				cout << -opps[j].second << '\n';break;
			}
		}
	}
	return 0;
};
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...