Submission #937630

#TimeUsernameProblemLanguageResultExecution timeMemory
937630kccStone Arranging 2 (JOI23_ho_t1)C++17
0 / 100
1 ms348 KiB
#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]);
			
			i = v[it].second;
			
			
		}
		else ans.pb(a[i]);
		//cout << a[i] << "\n";
	}
	
	for(auto w : ans) cout << w << "\n";
	return 0;
}

//按照顏色排序,從位置編號小的開始找



#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...