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 pb push_back
#define KCC ios::sync_with_stdio(0);cin.tie(0);
long long a[1000000];
set<pair<int, int>> s;
// 數字,位置
vector<int> ans;
vector<pair<int, int>> v;
int main()
{
KCC
int n;
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < n; i++) v.pb({a[i], i});
sort(v.begin(), v.end());
//for(int i = 0; i < n; i++) cout << v[i].first << ' ' << v[i].second << "\n";
for(int i = 0; i < n; i++){
pair<int, int> x = {a[i], i};
auto it = upper_bound(v.begin(), v.end(), x) - v.begin();
if(v[it].first == a[i]){
for(int j = i; j <= v[it].second; j++) ans.pb(a[i]);
ans.pop_back();
i = v[it].second - 1;
}
else ans.pb(a[i]);
}
for(auto w : ans) cout << w << "\n";
return 0;
}
//按照顏色排序,從位置編號小的開始找
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |