Submission #974301

#TimeUsernameProblemLanguageResultExecution timeMemory
974301modwweEvent Hopping 2 (JOI21_event2)C++17
100 / 100
165 ms58692 KiB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
//#define int long long
//#define ll long long
#define down cout<<'\n';
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
void ngha();
const int mod2=1e9+7;
const int  mod1=998244353;
struct ib
{
    int a;
    int b;
};
struct icd
{
    int a,b;
};
struct ic
{
    int a,b,c;
};
struct id
{
    int a,b,c,d;
};
struct ie
{
    int a,b,c, d,e;

};
int n,m,s1,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l;
int  i,s10,s12;
int el=29;
main()
{
//#ifndef ONLINE_JUDGE
   /// fin(task),fou(task);
//#endif
    NHP
//modwwe
    //  cin>>res;
    ngha();

}
ic bit[1000001];
int bit2[1000001];
ic a[500002];
int b[500001];
ic c[500001];
int st[17][500002];
int g[1000003];
vector<int>v;
vector<int> v2;
bool cmp(ic a,ic b)
{
    return a.a<b.a;
}

void upd(int x,int y,int z,int cc)
{
    for(x; x<=2*n; x+=x&-x)
    {
        if(y>bit[x].a)
            bit[x].a=y,bit[x].b=z,bit[x].c=cc;
    }
    ///bit[x]=max(bit[x],y);
}
ic get(int x)
{
    int ss=0;
    for(x; x; x-=x&-x)
    {
        if(bit[x].a>bit[ss].a)ss=x;
    }
    return bit[ss];
}
void upd2(int x,int y)
{
    for(x; x; x-=x&-x)bit2[x]=min(bit2[x],y);
}
int get2(int x)
{
    int ss=1e9+1;
    for(x; x<=2*n; x+=x&-x) //cout<<x<<" "<<bit2[x]<<" "<<ss,down
    {
        ss=min(bit2[x],ss);
    }
    return ss;
}
int get3(int x,int y)
{
    int ss=0;
    for(int j=16; j>=0; --j)
    {
        if(g[st[j][x]]<=y)
        {
            //  cout<<g[st[j][x]]<<" "<<st[j][x]<<" "<<j<<" "<<x,down
            //if(j==17) cout<<j<<" "<<st[j][x],down
            x=st[j][x];
            ss+=(1<<j);
        }
    }
    return ss;
}
int get4(int x,int y)
{
    int ss=0;
    for(int j=16; j>=0; --j)
    {
        if(g[st[j][x]]<=y)
        {
            //  cout<<g[st[j][x]]<<" "<<st[j][x]<<" "<<j<<" "<<x,down
            //if(j==17) cout<<j<<" "<<st[j][x],down
            x=st[j][x];
            ss+=(1<<j);
        }
    }
    return ss;
}
vector<int> v3;
void ngha()
{
    cin>>n>>k;
    for(int i=1; i<=n; i++)
        cin>>a[i].a>>a[i].b,v.pb(a[i].a),v.pb(a[i].b),v3.pb(a[i].a),a[i].c=i;
    v3.pb(0);
    v3.pb(1e9+1);
    sort(v.begin(),v.end());
    sort(v3.begin(),v3.end());
    for(int i=1; i<=n; i++)
        a[i].a=lower_bound(v.begin(),v.end(),a[i].a)-v.begin()+1,
            a[i].b=lower_bound(v.begin(),v.end(),a[i].b)-v.begin()+1;
    ///c[i]=a[i];
    for(int i=1; i<=n; i++) c[i]=a[i];
    sort(a+1,a+1+n,cmp);
/// nhay nhi phan :/
    s2=a[n].b;
    s3=n;
    b[n]=n;
    b[n+1]=n+1;
    a[n+1].a=1e9+1;
    a[n+1].c=n+1;
    for(int i=0; i<=16; i++)
        st[i][n+1]=n+1;
    for(int i=n-1; i>=1; --i)
    {
        if(a[i].b<s2) s2=a[i].b,s3=i;
        b[i]=s3;
    }
    g[n+1]=1e9;
    for(int i=0; i<=n; ++i)
    {
        l=i+1;
        r=n;
        while(l<=r)
        {
            int mid=l+r>>1;
            if(a[mid].a>=a[i].b) r=mid-1;
            else l=mid+1;
        }
        st[0][a[i].c]=a[b[r+1]].c;
        if(a[r+1].a==1e9+1)
        {s8=lower_bound(v3.begin(),v3.end(),a[r+1].a)-v3.begin();
            if(g[a[i].c]==0) g[a[i].c]=s8;
            g[a[i].c]=min(g[a[i].c],s8);
        }
        else
        { s8=lower_bound(v3.begin(),v3.end(),v[a[r+1].a-1])-v3.begin();
            if(g[a[i].c]==0) g[a[i].c]=s8;
            g[a[i].c]=min(g[a[i].c],s8);
        }
        // cout<<i<<" "<<a[i].a<<" "<<b[r+1]<<" "<<a[b[r+1]].a<<" "<<r+1,down
///if(a[i].c==3) cout<<r+1<<" "<<g[a[i].c],down
    }
    for(int i=1; i<17; i++)
        for(int j=0; j<=n*2; j++)
            st[i][j]=st[i-1][st[i-1][j]];
    for(int i=1; i<=n*2; i++)
        bit[i]= {0,0,0},bit2[i]=1e9+1;
    for(int i=1; i<=n; i++)
        a[i]=c[i];
    /// cout<<get3(1,4)<<" "<<get3(0,2),down
    /// cout<<get3(0,2),down
    ///  cout<<st[0][1],down
    dem=0;
    // cout<<get3(1,11);
    mx2=get3(0,n+1);
    for(int i=1; i<=n; i++)
    {
        //cout<<i,down
        if(dem==k)
        {
            break;
        }
        ic ss2=get(a[i].a);
        if(ss2.b>a[i].a) continue;

        s2=ss2.c;
        s3=get2(a[i].a);
        if(a[i].b>s3) continue;
        if(s3==1e9+1) s3=lower_bound(v3.begin(),v3.end(),s3)-v3.begin();
        else s3=lower_bound(v3.begin(),v3.end(),v[s3-1])-v3.begin();
        s9=lower_bound(v3.begin(),v3.end(),v[a[i].a-1])-v3.begin();
        if(mx2-get3(s2,s3)+get3(s2,s9)+get3(i,s3)+1>=k)
        {
            mx2=mx2-get3(s2,s3)+get3(s2,s9)+get3(i,s3)+1;
            dem++;
            upd(a[i].a,a[i].a,a[i].b,i);
            upd2(a[i].a,a[i].a);
            v2.pb(i);

        }
    }
    if(dem==k)
        for(auto x:v2)
            cout<<x,down
                else cout<<-1;
}
/*
4 3
21 54
86 92
85 90
90 101



*/

Compilation message (stderr)

event2.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   45 | main()
      | ^~~~
event2.cpp: In function 'void upd(int, int, int, int)':
event2.cpp:72:9: warning: statement has no effect [-Wunused-value]
   72 |     for(x; x<=2*n; x+=x&-x)
      |         ^
event2.cpp: In function 'ic get(int)':
event2.cpp:82:9: warning: statement has no effect [-Wunused-value]
   82 |     for(x; x; x-=x&-x)
      |         ^
event2.cpp: In function 'void upd2(int, int)':
event2.cpp:90:9: warning: statement has no effect [-Wunused-value]
   90 |     for(x; x; x-=x&-x)bit2[x]=min(bit2[x],y);
      |         ^
event2.cpp: In function 'int get2(int)':
event2.cpp:95:9: warning: statement has no effect [-Wunused-value]
   95 |     for(x; x<=2*n; x+=x&-x) //cout<<x<<" "<<bit2[x]<<" "<<ss,down
      |         ^
event2.cpp: In function 'void ngha()':
event2.cpp:168:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  168 |             int mid=l+r>>1;
      |                     ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...