답안 #103279

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
103279 2019-03-29T12:49:10 Z LittleFlowers__ Examination (JOI19_examination) C++14
2 / 100
3000 ms 46276 KB
#include <bits/stdc++.h>
using namespace std;
const int SZ=1<<10;
int ptr=SZ;
char buffer[SZ];
inline char readchar(){if(ptr==SZ){fread(buffer,1,SZ,stdin); ptr=0;}return buffer[ptr++];}
#define in ({int x=0;int c=readchar(),n=0;for(;!isdigit(c);c=readchar()) n=(c=='-');for(;isdigit(c);c=readchar()) x=x*10+c-'0';n?-x:x;})
inline void out(int 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=(i->L->M > i->R->M ? i->L->M : i->R->M);
        i->M=(i->M > i->V ? i->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) out(ans[i]),putchar('\n');
}

Compilation message

examination.cpp: In member function 'void CTDL::splay(CTDL::id)':
examination.cpp:78: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:121:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(;i<=val.size();i+=i&-i) ret+=T[i].get(x);
          ~^~~~~~~~~~~~
examination.cpp: In function 'char readchar()':
examination.cpp:6:41: warning: ignoring return value of 'size_t fread(void*, size_t, size_t, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
 inline char readchar(){if(ptr==SZ){fread(buffer,1,SZ,stdin); ptr=0;}return buffer[ptr++];}
                                    ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 300 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 8 ms 1536 KB Output is correct
8 Correct 9 ms 1536 KB Output is correct
9 Correct 10 ms 1408 KB Output is correct
10 Correct 8 ms 1536 KB Output is correct
11 Correct 5 ms 768 KB Output is correct
12 Correct 5 ms 768 KB Output is correct
13 Correct 9 ms 1536 KB Output is correct
14 Correct 10 ms 1536 KB Output is correct
15 Correct 10 ms 1536 KB Output is correct
16 Correct 4 ms 640 KB Output is correct
17 Correct 26 ms 1536 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1622 ms 45904 KB Output is correct
2 Correct 1525 ms 46120 KB Output is correct
3 Correct 1589 ms 46128 KB Output is correct
4 Correct 456 ms 45936 KB Output is correct
5 Correct 327 ms 13424 KB Output is correct
6 Correct 81 ms 13424 KB Output is correct
7 Correct 1454 ms 46040 KB Output is correct
8 Correct 763 ms 46012 KB Output is correct
9 Correct 647 ms 46276 KB Output is correct
10 Correct 83 ms 9328 KB Output is correct
11 Execution timed out 3091 ms 45032 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1622 ms 45904 KB Output is correct
2 Correct 1525 ms 46120 KB Output is correct
3 Correct 1589 ms 46128 KB Output is correct
4 Correct 456 ms 45936 KB Output is correct
5 Correct 327 ms 13424 KB Output is correct
6 Correct 81 ms 13424 KB Output is correct
7 Correct 1454 ms 46040 KB Output is correct
8 Correct 763 ms 46012 KB Output is correct
9 Correct 647 ms 46276 KB Output is correct
10 Correct 83 ms 9328 KB Output is correct
11 Execution timed out 3091 ms 45032 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 300 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 8 ms 1536 KB Output is correct
8 Correct 9 ms 1536 KB Output is correct
9 Correct 10 ms 1408 KB Output is correct
10 Correct 8 ms 1536 KB Output is correct
11 Correct 5 ms 768 KB Output is correct
12 Correct 5 ms 768 KB Output is correct
13 Correct 9 ms 1536 KB Output is correct
14 Correct 10 ms 1536 KB Output is correct
15 Correct 10 ms 1536 KB Output is correct
16 Correct 4 ms 640 KB Output is correct
17 Correct 26 ms 1536 KB Output is correct
18 Correct 4 ms 640 KB Output is correct
19 Correct 1622 ms 45904 KB Output is correct
20 Correct 1525 ms 46120 KB Output is correct
21 Correct 1589 ms 46128 KB Output is correct
22 Correct 456 ms 45936 KB Output is correct
23 Correct 327 ms 13424 KB Output is correct
24 Correct 81 ms 13424 KB Output is correct
25 Correct 1454 ms 46040 KB Output is correct
26 Correct 763 ms 46012 KB Output is correct
27 Correct 647 ms 46276 KB Output is correct
28 Correct 83 ms 9328 KB Output is correct
29 Execution timed out 3091 ms 45032 KB Time limit exceeded
30 Halted 0 ms 0 KB -