Submission #797869

#TimeUsernameProblemLanguageResultExecution timeMemory
7978691binStone Arranging 2 (JOI23_ho_t1)C++14
100 / 100
157 ms16140 KiB
#include <bits/stdc++.h> using namespace std; #define all(v) v.begin(), v.end() typedef long long ll; const int NMAX = 2e5 + 5; int n, a[NMAX]; vector<int> ans; map<int, int> cnt; int main(void){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; stack<int> st; for(int i = 1; i <= n; i++) { cin >> a[i]; if(cnt[a[i]]){ while(a[st.top()] != a[i]) cnt[a[st.top()]]--, st.pop(); } else st.emplace(i), cnt[a[i]]++; } for(int i = n; i; i--){ ans.emplace_back(a[st.top()]); if(st.top() == i) st.pop(); } reverse(all(ans)); for(int& x : ans) cout << x << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...