Submission #797868

#TimeUsernameProblemLanguageResultExecution timeMemory
7978681binStone Arranging 2 (JOI23_ho_t1)C++14
35 / 100
19 ms2820 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], cnt[NMAX]; vector<int> ans; 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...