Submission #954807

#TimeUsernameProblemLanguageResultExecution timeMemory
954807OtalpStone Arranging 2 (JOI23_ho_t1)C++14
100 / 100
353 ms39620 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define pii pair<int, int> #define ff first #define ss second map<int, vector<pii> > q; int a[201000]; void solve(){ int n; cin>>n; set<pair<pii, int> > d; for(int i=1; i<=n; i++){ cin>>a[i]; if(q[a[i]].size() == 0){ q[a[i]].pb({i, i}); d.insert({{i, i}, a[i]}); continue; } pii h = q[a[i]].back(); //auto g = d.find({h, a[i]}); while(d.size() and (*d.rbegin()).ff >= h){ auto g = d.end(); g--; q[g -> ss].pop_back(); d.erase(g); } q[a[i]].pb({h.ff, i}); d.insert({{h.ff, i}, a[i]}); } for(auto h: d){ for(int i=h.ff.ff; i<=h.ff.ss; i++){ a[i] = h.ss; } } for(int i=1; i<=n; i++){ cout<<a[i]<<'\n'; } } int main(){ solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...