Submission #1294689

#TimeUsernameProblemLanguageResultExecution timeMemory
1294689kaiboyStone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
144 ms13368 KiB
#include <algorithm>
#include <iostream>
#include <map>

using namespace std;

const int N = 200000;

int aa[N], kk[N];
map<int, bool> used;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	int n; cin >> n;
	int m = 0;
	while (n--) {
		int a; cin >> a;
		if (!used[a]) {
			aa[m] = a;
			kk[m] = 1;
			m++;
			used[a] = true;
			continue;
		}
		int s = 1;
		while (aa[m - 1] != a)
			used[aa[m - 1]] = false, s += kk[--m];
		kk[m - 1] += s;
	}
	for (int h = 0; h < m; h++)
		while (kk[h]--)
			cout << aa[h] << '\n';
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...