제출 #774664

#제출 시각아이디문제언어결과실행 시간메모리
774664vjudge1Stone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
174 ms13680 KiB
#include <bits/stdc++.h> using namespace std; const int NM = 2e5; int n, a[NM+5]; map <int, int> cnt; stack <int> st; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; cnt[a[1]] = 1; st.push(1); for (int i = 2; i <= n; i++) if (cnt[a[i]] > 0){ while (a[st.top()] != a[i]){ cnt[a[st.top()]]--; st.pop(); } st.pop(); st.push(i); } else{ cnt[a[i]] = 1; st.push(i); } while (!st.empty()){ int cur = st.top(); st.pop(); if (!st.empty()){ for (int i = st.top()+1; i < cur; i++) a[i] = a[cur]; } else{ for (int i = 1; i < cur; i++) a[i] = a[cur]; } } 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...