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;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
void solve(){
int n,sz = 0;
cin >> n;
map < int , int > last;
stack < array < int , 3 > > v;
while(n--){
int x;cin >> x;
if(last.count(x)){
sz++;
while(v.size() and (last[x]-1) != (int)v.size()){
v.pop();
}
v.push({x,(v.size() ? v.top()[2] : 0)+1,sz});
}
else{
sz++;
v.push({x,sz,sz});
}
last[x] = v.size();
}
vector < array < int , 3 > > vv;
while(v.size()){
vv.push_back(v.top());
v.pop();
}
reverse(vv.begin() , vv.end());
for(auto itr : vv){
for(int j = 0;j<(itr[2] - itr[1] + 1);j++){
cout << itr[0] << '\n';
}
}
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int testcase = 1;//cin >> testcase;
while(testcase--)solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |