Submission #756508

#TimeUsernameProblemLanguageResultExecution timeMemory
756508michaoStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
634 ms63692 KiB
#include <bits/stdc++.h> #define int long long #define mp make_pair #define pb push_back #define ld long double #define pii pair<int,int> #define sz(x) (int)x.size() #define piii pair<pii,pii> #define precise cout<<fixed<<setprecision(10) #define st first #define nd second #define ins insert #define vi vector<int> #define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; const int MAX=2e5+5; int a[MAX]; set<pair<pii,int>>q; map<int,int>conv; set<int>pom; int reconv[MAX]; set<pii>segs[MAX]; void add(int l,int r,int c){ q.ins(mp(mp(l,r),c)); segs[conv[c]].ins(mp(l,r)); } void del(int l,int r,int c){ q.erase(mp(mp(l,r),c)); segs[conv[c]].erase(mp(l,r)); } int32_t main() { BOOST; int n; cin>>n; for (int i=1;i<=n;i++)cin>>a[i]; for (int i=1;i<=n;i++)pom.ins(a[i]); int cnt=1; for (auto it:pom){ reconv[cnt]=it; conv[it]=cnt; cnt++; } for (int i=1;i<=n;i++){ int colorcnv=conv[a[i]]; if (segs[colorcnv].empty()){ add(i,i,a[i]); } else{ int l=segs[colorcnv].rbegin()->st; int r=i; while (!q.empty()){ pair<pii,int>akt=*q.rbegin(); int l2=akt.st.st; int r2=akt.st.nd; int color=akt.nd; if (r2<l)break; if (l2>=l){ del(l2,r2,color); q.erase(akt); continue; } else{ assert(r2>=l && l2<l); del(l2,r2,color); assert(color!=a[i]); add(l2,l-1,color); } } add(l,r,a[i]); } } for (auto it:q){ for (int i=it.st.st;i<=it.st.nd;i++)cout<<it.nd<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...