# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
916514 | raypeng1729 | Stone Arranging 2 (JOI23_ho_t1) | C++17 | 147 ms | 28876 KiB |
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
signed main(){
ios::sync_with_stdio(false), cin.tie(0);
int n; cin >> n;
int a[n], id[n];
vector<int> v;
for(int i = 0; i < n; i++) cin >> a[i], v.push_back(a[i]);
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for(int i = 0; i < n; i++) id[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
vector<vector<int>> pos(n);
vector<int> to(n, -1);
int cur = n, fin = 0;
set<int> ext;
for(int i = 0; i < n; i++) ext.insert(i);
for(int i = 0; i < n; i++){
while(pos[id[i]].size() && !ext.count(pos[id[i]].back())) pos[id[i]].pop_back();
if(pos[id[i]].size()){
to[i] = pos[id[i]].back();
auto a = ext.lower_bound(to[i]);
while(*a != i){
ext.erase(a);
a = ext.lower_bound(to[i]);
}
}
pos[id[i]].push_back(i);
}
for(int i = n - 1; i >= 0; i--){
if(to[i] == -1) continue;
for(int j = i; j >= to[i]; j--) a[j] = a[i];
i = to[i] + 1;
}
for(int i = 0; i < n; i++) cout << a[i] << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |