This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n, a[N], p[N];
bool active[N];
int find(int x, bool del){
if (!active[x])
return p[x] = find(p[x], del);
else{
if (del){
active[x] = 0;
return find(x, 0);
}
return x;
}
}
int main(){
cin >> n;
for (int i = 1; i <= n; i ++)
cin >> a[i];
active[0] = 1;
int last = 0;
for (int i = 1; i <= n; i ++){
if (a[i] > 0){
active[i] = 1;
p[i] = last;
last = i;
cout << a[i] << endl;
}
else{
active[i] = 1;
cout << a[find(last, 1)] << endl;
}
}
}
# | 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... |