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;
int main(){
int n, ind=1, maior[300100]={};
cin >> n;
map<int,int> compress;
map<int,int> descompress;
vector<int> v(n);
vector<pair<pair<int,int>, int>> resp;
for(int i=0; i<n; i++){
cin >> v[i];
maior[i]=-1;
}
maior[n]=-1;
vector<int> aux=v;
sort(aux.begin(), aux.end());
compress[aux[0]]=ind;
descompress[ind]=aux[0];
ind++;
for(int i=1; i<n; i++){
if(aux[i]>aux[i-1]){
compress[aux[i]]=ind;
descompress[ind]=aux[i];
ind++;
}
}
for(int i=0; i<n; i++){
int cur=compress[v[i]];
if(maior[cur]!=-1)resp.push_back({{maior[cur], i}, descompress[cur]});
maior[cur]=i;
}
sort(resp.begin(), resp.end());
int ptr=0, ptr2=0, ultimo;
while(ptr<n){
while(ptr2<(int)resp.size() && ptr>resp[ptr2].first.first && ultimo!=resp[ptr2].second){
ptr2++;
}
if(ptr2==(int)resp.size())break;
if(ptr<resp[ptr2].first.first){
cout << v[ptr] << '\n';
ptr++;
continue;
}
while(ptr<=resp[ptr2].first.second){
cout << resp[ptr2].second << '\n';
ptr++;
}
ultimo=resp[ptr2].second;
ptr2++;
}
while(ptr<n){
cout << v[ptr] << '\n';
ptr++;
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:46:67: warning: 'ultimo' may be used uninitialized in this function [-Wmaybe-uninitialized]
46 | while(ptr2<(int)resp.size() && ptr>resp[ptr2].first.first && ultimo!=resp[ptr2].second){
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |