제출 #1076640

#제출 시각아이디문제언어결과실행 시간메모리
1076640dwuyStone Arranging 2 (JOI23_ho_t1)C++14
100 / 100
281 ms29420 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int MX = 200005; int n; int a[MX]; void nhap(){ cin >> n; for(int i=1; i<=n; i++) cin >> a[i]; } void solve(){ stack<int> st; map<int, vector<int>> mp; for(int i=1; i<=n; i++){ if(mp[a[i]].size()){ int p = mp[a[i]].back(); while(st.size() && st.top() >= p){ int u = st.top(); st.pop(); if(mp[a[u]].size() && mp[a[u]].back() == u) mp[a[u]].pop_back(); } } mp[a[i]].push_back(i); st.push(i); } int value = 0; for(int i=n; i>=1; i--){ if(st.size() && i == st.top()){ value = a[st.top()]; st.pop(); } a[i] = value; } for(int i=1; i<=n; i++) cout << a[i] << '\n'; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); nhap(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...