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;
int arr[400000];
int calculate(int x){
if(arr[x]>=0)return x;
stack<int> q;
q.push(arr[x]);
for(int i = x - 1; i > 0; i--){
if(arr[i] > q.top()) q.pop();
else q.push(arr[i]);
if(q.empty()) return calculate(i - 1);
}
return 0;
}
int main(){
int n; cin >> n;
n++;
arr[0] = 0;
for(int i = 1; i < n; i++) cin >> arr[i];
if(n <= 6000){
for(int i = 1; i < n; i++) cout << arr[calculate(i)] << '\n';
return 0;
}
int mn = 0;
for(int i = 1; i < n; i++) mn = min(mn, arr[i]);
if(mn >= -1){
stack<int> q;
q.push(0);
for(int i = 1; i < n; i++){
if(arr[i] > 0) q.push(arr[i]);
else q.pop();
cout << q.top() << '\n';
}
}else{
for(int i = 1; i < n - 1; i++) cout << "1\n";
cout << arr[calculate(n - 1)] << '\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... |