Submission #931505

#TimeUsernameProblemLanguageResultExecution timeMemory
931505pccStone Arranging 2 (JOI23_ho_t1)C++14
100 / 100
235 ms39416 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3,unroll-loops") #define pii pair<int,int> #define fs first #define sc second const int mxn = 2e5+10; int arr[mxn]; int N; map<int,vector<int>> mp; vector<pair<pii,int>> vv; set<int> st; int ans[mxn]; int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>N; for(int i = 1;i<=N;i++)cin>>arr[i]; for(int i = 1;i<=N;i++){ vector<int> &v = mp[arr[i]]; st.insert(i); while(!v.empty()&&st.find(v.back()) == st.end())v.pop_back(); if(!v.empty()){ int l = v.back(); while(!vv.empty()&&vv.back().fs.fs>=l)vv.pop_back(); vv.push_back(make_pair(make_pair(l,i),arr[i])); vector<int> vvv; for(auto it = st.lower_bound(l);*it<i;it++){ vvv.push_back(*it); } for(auto &j:vvv)st.erase(j); } else{ vv.push_back(make_pair(make_pair(i,i),arr[i])); } mp[arr[i]].push_back(i); } for(auto &i:vv){ for(int j = i.fs.fs;j<=i.fs.sc;j++)ans[j] = i.sc; } //for(auto &i:vv)cout<<i.fs.fs<<' '<<i.fs.sc<<':'<<i.sc<<endl; for(int i = 1;i<=N;i++){ cout<<ans[i]<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...