#include "bits/stdc++.h"
using namespace std;
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
int n;
cin >> n;
vector <int> v, active(n+1,0), par(n+1,-1), type(n+1, 0);
v.push_back(0);
type[0] = active[0] = true;
for(int i = 1; i <= n; i++){
int x;
cin >> x;
active[i] = true;
if(x > 0){
v.push_back(x);
type[i] = 1;
}
else {
x *= (-1);
v.push_back(x);
int k = -1;
for(int j = i-1; j > 0; j--){
if(active[j] and (v[j] < x or type[j])){
par[i] = j;
k = j;
break;
}
}
while(~k){
active[k] = (1-active[k]);
k = par[k];
}
}
int ans = 0;
for(int j = i; j >= 0; j--){
if(type[j] and active[j]){
ans = j;
break;
}
}
cout << v[ans] << '\n';
}
}
# | 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... |