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;
#define int long long
#define st first
#define nd second
const int maxn = 2e5 + 5;
int n, a[maxn];
map<int, int> mp;
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i = 1; i <= n ; i++)
cin >> a[i];
for(int i = 1 ; i <= n ; i++){
mp[a[i]] = i;
}
int ptr = 1;
vector<pair<int, pair<int, int>>> ans;
while(ptr <= n){
// cout << a[ptr] << " " << ptr << " " << mp[a[ptr]] << endl;
if(mp[a[ptr]] > ptr){
ans.push_back({a[ptr], {ptr, mp[a[ptr]]}});
}
else
ans.push_back({a[ptr], {ptr, ptr}});
ptr = mp[a[ptr]] + 1;
}
for(pair<int, pair<int, int>> v : ans){
for(int i = v.nd.st ; i <= v.nd.nd ; i++)
cout << v.st << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |