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;
using ll = long long;
int n;
vector<int> t;
int F(vector<int>& a, int val){
int l = 0, r = a.size() - 1, best = -1;
while(l <= r){
int mid = (l + r) / 2;
if(a[mid] >= val){
best = mid;
r = mid - 1;
}else{
l = mid + 1;
}
}
return a[best];
}
int main(){
cin >> n;
t.resize(n);
map<int, vector<int>> tmp;
for(int i = 0; i < n; i++){
cin >> t[i];
tmp[t[i]].push_back(i);
}
int ind = 0, val;
while(ind < n){
val = t[ind];
vector<int> a = tmp[val];
if(a.size() == 1){
cout << val;
ind++;
}
int start = F(a, ind);
int end = a.back();
//cout << start << ' ' << end << "; val - " << val << '\n';
for(int i = start; i <= end; i++) cout << val << '\n';
ind = end + 1;
}
}
// 1 2 3 1 3 2 3 4 1 2 3 5 5 4
// 1 1 1 1 1 1 1 1 1 2 3 5 5 4
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |