Submission #544552

#TimeUsernameProblemLanguageResultExecution timeMemory
544552leakedEvent Hopping 2 (JOI21_event2)C++14
100 / 100
180 ms21880 KiB
#include <bits/stdc++.h> #define f first #define s second #define m_p make_pair #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define vec vector #define pb push_back #define sz(x) (int)(x).size() #define pw(x) (1LL<<(x)) #define fast_resp ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef long double ld; template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);} template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);} const int N=2e5+1; int up[N][20]; signed main(){ fast_resp; int n,k; cin>>n>>k; vec<int>l(n),r(n); vec<int> kek; for(int i=0;i<n;i++){ cin>>l[i]>>r[i]; ++l[i]; kek.pb(l[i]);kek.pb(r[i]); } sort(all(kek));kek.erase(unique(all(kek)),kek.end()); for(auto &z : l) z=lower_bound(all(kek),z)-kek.begin(); for(auto &z : r) z=lower_bound(all(kek),z)-kek.begin(); for(int i=0;i<sz(kek);i++){ for(int j=0;j<20;j++) up[i][j]=1e9; } for(int i=0;i<n;i++){ umin(up[l[i]][0],r[i]); } for(int j=0;j<20;j++){ if(j){ for(int i=0;i<sz(kek);i++){ // up[i][j]=up[i][j-1]; // cerr, if(up[i][j-1]+1<sz(kek)){ up[i][j]=up[up[i][j-1]+1][j-1]; }else up[i][j]=1e9; } } for(int i=sz(kek)-1;i>=1;i--){ umin(up[i-1][j],up[i][j]); } // for(int i=0;i<sz(kek);i++){ // cerr<<"HEY "<<i<<' '<<j<<' '<<up[i][j]<<endl; // } } auto get=[&](int l,int r){ int cnt=0; for(int i=19;i>=0;i--){ if(l<=r && up[l][i]<=r){ cnt+=pw(i); l=up[l][i]+1; } } return cnt; }; if(get(0,sz(kek)-1)<k){ cout<<-1; return 0; } set<pii> st; st.insert({0,sz(kek)-1}); vec<int> added; int cool=get(0,sz(kek)-1); int total=cool; for(int i=0;i<n;i++){ auto it=st.lower_bound(m_p(l[i],-1)); if(it!=st.begin()) --it; if(it!=st.end() && it->s<l[i]) ++it; // for(auto &z : st) // cout<<z.f<<' '<<z.s<<endl; if(it==st.end()) continue; if(it->s<r[i] || it->f>l[i]) continue; int ins=get(it->f,l[i]-1)+get(r[i]+1,it->s)+1; int have=ins-get(it->f,it->s)+total; // cout<<"TOADD "<<i<<' '<<have<<' '<<ins<<' '<<total<<' '<<get(it->f,it->s)<<endl; if(have<k || sz(added)==k) continue; total-=get(it->f,it->s); total+=ins; // cout<<"TOADD "<<i<<endl; added.pb(i); pii c=*it; st.erase(it); // cout<<l[i]<<' '<<r[i]<<' '<<c.f<<' '<<c.s<<endl; if(c.f<l[i]) st.insert({c.f,l[i]-1}); if(r[i]<c.s) { st.insert({r[i]+1,c.s}); // cout<<"ED "<<c.s+1<<' '<<r[i]<<endl; } } // assert(sz(added)==k); for(auto &z : added) cout<<z+1<<'\n'; return 0; } /* */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...