Submission #659183

# Submission time Handle Problem Language Result Execution time Memory
659183 2022-11-16T23:34:39 Z zaneyu Event Hopping 2 (JOI21_event2) C++14
0 / 100
110 ms 24428 KB
/*input
5 4
1 3
2 5
8 9
6 8
10 15
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace __gnu_pbds;
typedef tree<long long,null_type,less_equal<long long>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key #of elements less than x
// find_by_order kth element
using ll=long long;
using ld=long double;
using pii=pair<ll,ll>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET(v,x) lower_bound(ALL(v),x)-v.begin()
const int maxn=2e5+5;
const ll INF=0x3f3f3f3f;
const ld PI=acos(-1.0l);
const ld eps=1e-6;
const ll INF64=4e18+1;
const int MOD=1e9+7;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
    out<<P.f<<' '<<P.s;
    return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
    REP(i,sz(V)) out<<V[i]<<((i!=sz(V)-1)?"\n":"");
    return out;
}
inline ll mult(ll a,ll b){
    return a*b%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int l[maxn],r[maxn];
int suff[maxn];
int mn[maxn][20];
int get(int l,int r){
    int ans=0;
    for(int j=19;j>=0;j--){
        if(mn[l][j]<=r){
            l=mn[l][j];
            ans+=(1<<j);
        }
    }
    return ans;
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n,k;
    cin>>n>>k;
    vector<pii> v;
    vector<int> dsc;
    REP(i,n){
        cin>>l[i]>>r[i];
        //--r[i];
        dsc.pb(l[i]),dsc.pb(r[i]);
    }
    SORT_UNIQUE(dsc);
    REP(i,2*n) suff[i]=INF;
    REP(i,n){
        l[i]=GET(dsc,l[i]),r[i]=GET(dsc,r[i]);
        MNTO(suff[l[i]],r[i]);
    }  
    for(int i=2*n-2;i>=0;i--) MNTO(suff[i],suff[i+1]);
    REP(i,2*n){
        mn[i][0]=suff[i];
    }
    REP1(j,19){
        REP(i,2*n){
            if(i+(1<<j)>2*n) break;
            if(mn[i][j-1]<INF) mn[i][j]=mn[mn[i][j-1]][j-1];
            else mn[i][j]=INF;
        }
    }
    set<pii> s;
    s.insert({0,0}),s.insert({2*n-1,2*n-1});
    vector<int> ans;
    REP(i,n){
        auto it=s.lower_bound({l[i],r[i]});
        if((it!=s.begin() and (*prev(it)).s>l[i]) or (it!=s.end() and ((*it).f)<r[i])){
            continue;
        }
        if(sz(s)+1+get((*prev(it)).s,l[i])+get(r[i],(*it).f)>=k){
            s.insert({l[i],r[i]});
            ans.pb(i+1);
        }
        if(sz(ans)==k) break;
    }
    if(sz(ans)!=k) cout<<-1;
    else cout<<ans;
}   
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Incorrect 110 ms 24428 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Incorrect 110 ms 24428 KB Output isn't correct
5 Halted 0 ms 0 KB -