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>
#define ff first
#define ss second
using namespace std;
using ll = long long;
int n;
vector<int> a;
int G(const vector<int>& b, ll x){
int l = 0, r = b.size() - 1;
while(r - l > 1){
int mid = (l + r) / 2;
if(a[mid] > x) r = mid - 1;
else l = mid;
}
return b[l];
}
int main(){
cin >> n;
a.resize(n);
map<int, vector<int>> tmp;
for(int i = 0; i < n; i++) cin >> a[i], tmp[a[i]].push_back(i);
int id = 0;
while(id < n){
int cur = a[id];
const vector<int>& positions = tmp[cur];
int start = G(positions, id), end = positions.back();
//cout << id << " ---> " << start << ' ' << end << '\n';
for(int i = start; i <= end; i++) cout << a[cur] << '\n';
id = end + 1;
if(id > n) break;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |