Submission #405562

#TimeUsernameProblemLanguageResultExecution timeMemory
405562dvdg6566Event Hopping 2 (JOI21_event2)C++14
32 / 100
3029 ms8444 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pi; typedef vector<ll> vi; typedef vector<pi> vpi; #define pb emplace_back #define f first #define s second #define mp make_pair #define SZ(x) (ll)x.size() #define ALL(x) x.begin(),x.end() #define lb lower_bound #define ub upper_bound const int MAXN = 200100; int L[MAXN]; vpi V; vi des; int N,a,b,M,K; int eval(int x,int y){ int ans=0; while(x<=y&&L[x]<=y){ // fits within (x,y) x = L[x]+1; ++ans; } return ans; } set<pair<pi,int>> S; int main(){ cin>>N>>K; for(int i=0;i<N;++i){ cin>>a>>b; --b; V.pb(a,b); des.pb(a);des.pb(b); } sort(ALL(des));des.resize(unique(ALL(des))-des.begin()); for(auto &i:V){ i.f = lb(ALL(des),i.f) - des.begin(); i.s = lb(ALL(des),i.s) - des.begin(); // cerr<<i.f<<' '<<i.s<<'\n'; } vpi T; for(auto i:V)T.pb(i); sort(ALL(T)); M=SZ(des)-1; // run from 0 to M-1 ll rc=1e9; for(int i=M;i>=0;--i){ while(SZ(T)&&T.back().f>=i){ rc=min(rc,T.back().s); T.pop_back(); } L[i]=rc; } // for(int i=0;i<=M;++i)cerr<<L[i]<<' ';cerr<<'\n'; int tot=eval(0,M); // cerr<<tot<<'\n'; if(tot<K){ cout<<-1<<'\n'; return 0; } S.insert(mp(mp(-1,-1),-1)); S.insert(mp(mp(0,M),tot)); // for(auto i:S){ // cerr<<i.f.f<<' '<<i.f.s<<'\n'; // } vi ans; for(int i=0;i<N;++i){ a = V[i].f; b = V[i].s; auto x = --S.ub(mp(mp(a,1e9),-1e9)); pi rng=x->f; // cerr<<rng.f<<' '<<rng.s<<'\n'; int w=x->s; if(rng.f>a)assert(0); if(rng.s<b)continue; // rng.f, a, b, rng.s int c=eval(rng.f,a-1); int d=eval(b+1,rng.s); int nv=c+d; if(tot-w+1+nv<K)continue; // cannot take tot = tot-w+1+nv; ans.pb(i+1); S.erase(x); if(c)S.insert(mp(mp(rng.f,a-1),c)); if(d)S.insert(mp(mp(b+1,rng.s),d)); // cerr<<"Ins "<<i+1<<'\n'; } while(SZ(ans)>K)ans.pop_back(); for(auto i:ans)cout<<i<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...