Submission #837967

#TimeUsernameProblemLanguageResultExecution timeMemory
837967gun_ganStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
150 ms15184 KiB
#include <bits/stdc++.h> using namespace std; const int MX = 2e5 + 5; int A[MX]; map<int,int> cnt; int N; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> N; for(int i = 1; i <= N; i++) cin >> A[i]; vector<int> v; for(int i = 1; i <= N; i++) { if(cnt[A[i]] > 0) { while(!v.empty() && A[v.back()] != A[i]) { cnt[A[v.back()]]--; v.pop_back(); } } cnt[A[i]]++; v.push_back(i); } for(int i = N; i >= 1; i--) { A[i] = A[v.back()]; if(v.back() == i) v.pop_back(); } for(int i = 1; i <= N; i++) cout << A[i] << " "; cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...