Submission #781749

#TimeUsernameProblemLanguageResultExecution timeMemory
781749borisAngelovStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
127 ms16220 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int n; int a[maxn]; void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fastIO(); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } multiset<int> s; stack<pair<int, int>> st; for (int i = 1; i <= n; ++i) { if (s.find(a[i]) == s.end()) { //cout << "here for " << i << endl; st.push(make_pair(a[i], i)); s.insert(a[i]); } else { //cout << "popping on " << i << ' ' << st.size() << endl; while (st.top().first != a[i]) { //cout << "removing " << st.top().first << ' ' << st.top().second << endl; s.erase(s.find(st.top().first)); st.pop(); } } } int last = n; while (!st.empty()) { int col = st.top().first; int idx = st.top().second; st.pop(); for (int i = last; i >= idx; --i) { a[i] = col; } last = idx - 1; } 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...