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;
using ll = long long;
const int N = 2e5 + 10;
int n;
int a[N];
vector<int> st[N];
map<int, int> mp, key;
void compose() {
for(int i = 0; i < n; i++)
mp[a[i]] = 1;
int k = 0;
for(auto &c : mp) {
c.second = k++;
key[c.second] = c.first;
}
for(int i = 0; i < n; i++)
a[i] = mp[a[i]];
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n;
for(int i = 0; i < n; i++)
cin >> a[i];
compose();
for(int i = 0; i < n; i++) {
if(st[a[i]].empty()) st[a[i]].push_back(i);
else {
int lst = st[a[i]].back();
for(int j = i - 1; j > lst; j--)
st[a[j]].pop_back();
while(lst < i) {
a[++lst] = a[i];
st[a[lst]].push_back(lst);
}
}
}
for(int i = 0; i < n; i++)
cout << key[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... |