Submission #103278

# Submission time Handle Problem Language Result Execution time Memory
103278 2019-03-29T12:44:26 Z LittleFlowers__ Examination (JOI19_examination) C++14
2 / 100
3000 ms 46204 KB
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
inline void out(long long x){if(x<0) putchar('-'),x=-x;if(x>9) out(x/10);putchar(x%10+'0');}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define task "EXAMiNATION"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))

const int N=100010;

int n,q;
struct tp{int x,y,z,i;}a[N],t[N];

int ans[N];
vector<int> val;


struct CTDL{
    struct oo;
    typedef oo* id;

    struct oo{
        id L,R,P;
        int S,V,M; /// dung coi thuong nguoi khac
    };
    id F,G;
    void build(){
        F=new oo;
        F->S=F->V=F->M=0;
        F->P=F->L=F->R=F;
        G=F;
    }
    id init(int x){
        id y=new oo;
        y->P=y->L=y->R=F;
        y->S=1; y->V=y->M=x;
        return y;
    }
    void lef(id p,id u){p->L=u,u->P=p;}
    void rig(id p,id u){p->R=u,u->P=p;}
    void down(id i){
        if(i==F) return;
        i->S=i->L->S+i->R->S+1;
        i->M=max({i->L->M,i->R->M,i->V});
    }
    void up(id x){
        id y=x->P,z=y->P;
        if(y->L==x) lef(y,x->R),rig(x,y);
        else        rig(y,x->L),lef(x,y);
        if(z->L==y) lef(z,x);
        else        rig(z,x);
        down(y),down(x),down(z);
    }
    void splay(id x){
        for(;;){
            id y=x->P,z=y->P;
            if(y==F){
                G=x;
                return;
            }
            if(z!=F) if((z->L==y)==(y->L==x)) up(y);
                     else up(x);
            up(x);
        }
    }
    id pos(id x,int i){
        if(x==F) return x;
        if(x->L->M>=i) return pos(x->L,i);
        if(x->V<i) return pos(x->R,i);
        return x;
    }
    void dfs(id x,id y){
        if(x==F) return;
        if(x->V<y->V){
            if(x->R==F) rig(x,y);
            else dfs(x->R,y);
        }
        else{
            if(x->L==F) lef(x,y);
            else dfs(x->L,y);
        }
        down(x);
    }
    void add(int x){
        id y=init(x);
        dfs(G,y);
        splay(y);
    }
    int get(int x){
        id tmp=pos(G,x);
        if(tmp==F) return 0;
        splay(tmp);
        return G->R->S+1;
    }
}T[N];


void upd(int i,int x){
    for(;i;i-=i&-i) T[i].add(x);
}
int que(int i,int x){
    i=lower_bound(all(val),i)-val.begin()+1;
    int ret=0;
    for(;i<=val.size();i+=i&-i) ret+=T[i].get(x);
    return ret;
}

signed main(){
    //freopen("EXAMiNATION.inp","r",stdin);
    //freopen("EXAMiNATION.out","w",stdout);
    n=in,q=in;
    forinc(i,1,n){
        int x=in,y=in; a[i]={x,y+1,x+y}; val.pb(x);
    }
    forinc(i,1,q) t[i]={in,in+1,in,i};

    sort(all(val)); val.erase(unique(all(val)),val.end());
    forinc(i,1,n) a[i].x=lower_bound(all(val),a[i].x)-val.begin()+1;

    sort(a+1,a+n+1,[](tp i, tp j){return i.z>j.z;});
    sort(t+1,t+q+1,[](tp i, tp j){return i.z>j.z;});
    forinc(i,1,val.size()) T[i].build();

    int j=1;
    forinc(i,1,q){
        while(j<=n && a[j].z>=t[i].z){
            upd(a[j].x,a[j].y); j++;
        }
        ans[t[i].i]=que(t[i].x,t[i].y);
    }
    forinc(i,1,q) cout<<ans[i]<<"\n";
}

Compilation message

examination.cpp: In member function 'void CTDL::splay(CTDL::id)':
examination.cpp:73:15: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
             if(z!=F) if((z->L==y)==(y->L==x)) up(y);
               ^
examination.cpp: In function 'int que(int, int)':
examination.cpp:116:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(;i<=val.size();i+=i&-i) ret+=T[i].get(x);
          ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 14 ms 1408 KB Output is correct
8 Correct 17 ms 1408 KB Output is correct
9 Correct 13 ms 1408 KB Output is correct
10 Correct 11 ms 1408 KB Output is correct
11 Correct 5 ms 768 KB Output is correct
12 Correct 5 ms 768 KB Output is correct
13 Correct 10 ms 1408 KB Output is correct
14 Correct 12 ms 1408 KB Output is correct
15 Correct 15 ms 1408 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 27 ms 1408 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1637 ms 45952 KB Output is correct
2 Correct 1604 ms 46204 KB Output is correct
3 Correct 1611 ms 46012 KB Output is correct
4 Correct 486 ms 45852 KB Output is correct
5 Correct 352 ms 13524 KB Output is correct
6 Correct 81 ms 13424 KB Output is correct
7 Correct 1367 ms 45928 KB Output is correct
8 Correct 953 ms 46060 KB Output is correct
9 Correct 638 ms 46064 KB Output is correct
10 Correct 92 ms 9456 KB Output is correct
11 Execution timed out 3030 ms 45048 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1637 ms 45952 KB Output is correct
2 Correct 1604 ms 46204 KB Output is correct
3 Correct 1611 ms 46012 KB Output is correct
4 Correct 486 ms 45852 KB Output is correct
5 Correct 352 ms 13524 KB Output is correct
6 Correct 81 ms 13424 KB Output is correct
7 Correct 1367 ms 45928 KB Output is correct
8 Correct 953 ms 46060 KB Output is correct
9 Correct 638 ms 46064 KB Output is correct
10 Correct 92 ms 9456 KB Output is correct
11 Execution timed out 3030 ms 45048 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 14 ms 1408 KB Output is correct
8 Correct 17 ms 1408 KB Output is correct
9 Correct 13 ms 1408 KB Output is correct
10 Correct 11 ms 1408 KB Output is correct
11 Correct 5 ms 768 KB Output is correct
12 Correct 5 ms 768 KB Output is correct
13 Correct 10 ms 1408 KB Output is correct
14 Correct 12 ms 1408 KB Output is correct
15 Correct 15 ms 1408 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 27 ms 1408 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
19 Correct 1637 ms 45952 KB Output is correct
20 Correct 1604 ms 46204 KB Output is correct
21 Correct 1611 ms 46012 KB Output is correct
22 Correct 486 ms 45852 KB Output is correct
23 Correct 352 ms 13524 KB Output is correct
24 Correct 81 ms 13424 KB Output is correct
25 Correct 1367 ms 45928 KB Output is correct
26 Correct 953 ms 46060 KB Output is correct
27 Correct 638 ms 46064 KB Output is correct
28 Correct 92 ms 9456 KB Output is correct
29 Execution timed out 3030 ms 45048 KB Time limit exceeded
30 Halted 0 ms 0 KB -