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>
#define int long long
#define f first
#define s second
using namespace std;
signed main() {
int n; cin >> n; map<int,int> m;
stack<pair<int,int>> t;
for(int i=0;i<n;i++) {
int x; cin >> x;
if(m[x]) {
int c = 1; while(t.top().f != x) {c += t.top().s, m[t.top().f]--; t.pop();}
int y = t.top().s; t.pop(); t.push({x,y+c});
}
else {t.push({x,1}); m[x]++;}
}
vector<int> v(n); int k=n-1;
stack<pair<int,int>> q = t;
while(!t.empty()) {
for(int i=0;i<t.top().s;i++) v[k-i] = t.top().f;
k -= t.top().s; t.pop();
}
for(auto i:v) cout << 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... |