This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//JOI 2023 Final Round
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for(int i=0; i<n; i++){
cin >> a[i];
}
vector<int> stack;
stack.push_back(-1);
map<int,int> cnt;
for(int i=0; i<n; i++){
cnt[a[i]]++;
if(cnt[a[i]]==1){
stack.push_back(i);
continue;
}
while(!stack.empty() && a[stack.back()]!=a[i]){
cnt[a[stack.back()]]--;
stack.pop_back();
}
stack.push_back(i);
}
vector<int> col(n);
int s=stack.size();
for(int i=s-1; i>0; i--){
for(int j=stack[i]; j>stack[i-1]; j--){
col[j] = a[stack[i]];
}
}
for(auto e: col){
cout << e << "\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... |