Submission #937794

#TimeUsernameProblemLanguageResultExecution timeMemory
937794weakweakweakStone Arranging 2 (JOI23_ho_t1)C++14
100 / 100
129 ms15304 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") int n, a[310000]; int main () { ios_base :: sync_with_stdio(false); cin.tie(0); multiset <int> mst; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; mst.insert(a[1]); vector <int> v = {1}; for (int i = 2; i <= n; i++) { if (mst.find(a[i]) == mst.end()) { mst.insert(a[i]); v.push_back(i); } else { while (v.size()) { int j = v.back(); mst.erase(mst.find(a[j])); v.pop_back(); if (a[j] == a[i]) break; } v.push_back(i); mst.insert(a[i]); } } int now = a[v . back()]; for (int i = n; i >= 1; i--) { if (v.size() and i == v.back()) { now = a[v.back()]; v.pop_back(); } a[i] = now; } for (int i = 1; i <= n; i++) cout << a[i] << '\n'; return 0;}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...