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;
cin >> n;
vector<pair<int , int>> v;
vector<int> bef(n + 1) , a(n + 1);
for(int i = 1;i <= n;i ++){
cin >> bef[i];
v.push_back({bef[i] , i});
}
sort(v.begin() , v.end());
for(int i = 0;i < n;i ++){
a[v[i].second] = (i == 0 ? 1 : a[v[i - 1].second] + (v[i].first != v[i - 1].first));
}
vector<int> color(n + 1);
set<int> alive , p[n + 1];
for(int i = 1;i <= n;i ++){
if(!p[a[i]].empty()){
int pos = *--p[a[i]].end();
while(alive.upper_bound(pos) != alive.end()){
auto it = alive.upper_bound(pos);
color[*it] = i;
p[a[*it]].erase(*it);
alive.erase(*it);
}
}
p[a[i]].insert(i);
alive.insert(i);
}
for(int i = n;i >= 1;i --){
color[i] = (color[i] == 0 ? bef[i] : color[color[i]]);
}
for(int i = 1;i <= n;i ++){
cout << color[i] << " ";
}
cout << 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... |