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 a[200001], noi[200001];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
for(int i = 1; i <= n; i++) cin>>a[i];
unordered_map<int, int> f;
stack<int> num;
for(int i = 1; i <= n; i++){
int &val = f[a[i]];
if(val > 0){
while(num.size() > 0 && a[num.top()] != a[i]){
f[a[num.top()]]--;
num.pop();
}
noi[i] = num.top();
}
num.push(i);
val++;
}
for(int i = n; i >= 1; i--) if(noi[i] > 0){
int x = noi[i], cur = a[i];
while(i > x+1){
i--;
a[i] = cur;
}
}
for(int i = 1; i <= n; i++) cout<<a[i]<<'\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... |