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 mx = 3e5+5;
int n, ans[mx], up[mx][19], mn[mx][19];
int main(){
cin >> n;
for (int i = 1; i <= n; i++){
int a; cin >> a; if (a > 0){ ans[i] = a; continue; }
a *= -1; int pos = i-1;
for (int l = 18; l >= 0; l--) if (mn[pos][l] >= a) pos = up[pos][l];
up[i][0] = pos-1, mn[i][0] = a, ans[i] = ans[pos-1];
for (int l = 1; l < 18; l++){
up[i][l] = up[up[i][l-1]][l-1];
mn[i][l] = min(mn[i][l-1], mn[up[i][l-1]][l-1]);
}
}for (int i = 1; i <= n; i++) cout<<ans[i]<<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... |