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;
void AC()
{
int n; cin >> n;
vector<int> A(n);
for(int i=0;i<n;i++){cin >> A[i] ;}
map<int,bool> vis;
vector<pair<int,int>> que;
for(int i = 0; i < n; i++)
{ if(!vis[A[i]]){vis[A[i]]=true; que.push_back({1,A[i]}) ;}
else{ int cnt=1; while(que.back().second != A[i]){cnt+=que.back().first; vis[que.back().second]=false; que.pop_back();} que.push_back({cnt, A[i]}) ;}
}
for(auto pr: que){
for(int i = 0; i < pr.first; i++) {cout << pr.second << endl;}
}
}
int main()
{
//freopen("ip.txt", "r", stdin);
//freopen("op.txt", "w", stdout);
int t = 1;
// cin >> t;
while(t--)
{
AC();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |