# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
924031 | Sunbae | Stone Arranging 2 (JOI23_ho_t1) | C++17 | 37 ms | 10808 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;
const int N = 200005;
int A[N], val[N], m;
vector<int>C;
int pos(int x){return lower_bound(C.begin(), C.end(), x) - C.begin();}
int B[N];
vector<int> V[N];
bool cmp(int x, int y){return V[x].front() < V[y].front();}
signed main(){
int n; scanf("%d", &n);
for(int i = 0; i<n; ++i) scanf("%d", A+i), C.push_back(A[i]);
sort(C.begin(), C.end());
C.resize(unique(C.begin(), C.end()) - C.begin());
m = C.size();
for(int i = 0; i<m; ++i) val[i] = C[i];
for(int i = 0; i<n; ++i) A[i] = pos(A[i]);
for(int i = 0; i<n; ++i) V[A[i]].push_back(i);
for(int i = 0; i<m; ++i) B[i] = i;
sort(B, B+m, cmp);
int Right = -1;
for(int i = 0; i<m; ++i){
int x = B[i];
int l = max(Right+1, V[x].front());
int r = V[x].back();
if(l > r) continue;
for(int j = l; j<=r; ++j) printf("%d\n", val[x]);
Right = max(Right, r);
}
}
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... |