Submission #956252

#TimeUsernameProblemLanguageResultExecution timeMemory
956252Dalek_of_RiviaStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
368 ms16208 KiB
#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(nullptr); int T=1; //cin>>T; for(int dalekofrivia=T; dalekofrivia>0; dalekofrivia--){ int N; cin>>N; int color[N]; map<int, int> m; stack<pair<int, int>> Q; for(int i=1; i<=N; i++){ int h; cin>>h; if(m[h]==0){ m[h]++; pair<int, int> p(i, h); Q.push(p); }else{ while(Q.top().second!=h){ m[Q.top().second]--; Q.pop(); } Q.pop(); pair<int, int> p(i, h); Q.push(p); } } int C = Q.top().second; Q.pop(); for(int i=N-1; i>=0; i--){ if(Q.empty()){ color[i]=C; }else if(i>=Q.top().first){ color[i]=C; }else{ C=Q.top().second; Q.pop(); color[i]=C; } } for(int u: color) cout<<u<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...