답안 #103277

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
103277 2019-03-29T12:43:34 Z LittleFlowers__ Examination (JOI19_examination) C++14
2 / 100
3000 ms 63388 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#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:74: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 'long long int que(long long int, long long int)':
examination.cpp:117:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(;i<=val.size();i+=i&-i) ret+=T[i].get(x);
          ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 9 ms 1920 KB Output is correct
8 Correct 11 ms 1920 KB Output is correct
9 Correct 14 ms 1920 KB Output is correct
10 Correct 11 ms 1920 KB Output is correct
11 Correct 5 ms 896 KB Output is correct
12 Correct 4 ms 1024 KB Output is correct
13 Correct 14 ms 1920 KB Output is correct
14 Correct 10 ms 1920 KB Output is correct
15 Correct 14 ms 1920 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 29 ms 1912 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1802 ms 63388 KB Output is correct
2 Correct 1780 ms 63372 KB Output is correct
3 Correct 1540 ms 63312 KB Output is correct
4 Correct 409 ms 63260 KB Output is correct
5 Correct 377 ms 20200 KB Output is correct
6 Correct 88 ms 20208 KB Output is correct
7 Correct 1286 ms 63344 KB Output is correct
8 Correct 745 ms 63332 KB Output is correct
9 Correct 857 ms 63320 KB Output is correct
10 Correct 131 ms 14828 KB Output is correct
11 Execution timed out 3030 ms 62060 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1802 ms 63388 KB Output is correct
2 Correct 1780 ms 63372 KB Output is correct
3 Correct 1540 ms 63312 KB Output is correct
4 Correct 409 ms 63260 KB Output is correct
5 Correct 377 ms 20200 KB Output is correct
6 Correct 88 ms 20208 KB Output is correct
7 Correct 1286 ms 63344 KB Output is correct
8 Correct 745 ms 63332 KB Output is correct
9 Correct 857 ms 63320 KB Output is correct
10 Correct 131 ms 14828 KB Output is correct
11 Execution timed out 3030 ms 62060 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 2 ms 384 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 9 ms 1920 KB Output is correct
8 Correct 11 ms 1920 KB Output is correct
9 Correct 14 ms 1920 KB Output is correct
10 Correct 11 ms 1920 KB Output is correct
11 Correct 5 ms 896 KB Output is correct
12 Correct 4 ms 1024 KB Output is correct
13 Correct 14 ms 1920 KB Output is correct
14 Correct 10 ms 1920 KB Output is correct
15 Correct 14 ms 1920 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 29 ms 1912 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
19 Correct 1802 ms 63388 KB Output is correct
20 Correct 1780 ms 63372 KB Output is correct
21 Correct 1540 ms 63312 KB Output is correct
22 Correct 409 ms 63260 KB Output is correct
23 Correct 377 ms 20200 KB Output is correct
24 Correct 88 ms 20208 KB Output is correct
25 Correct 1286 ms 63344 KB Output is correct
26 Correct 745 ms 63332 KB Output is correct
27 Correct 857 ms 63320 KB Output is correct
28 Correct 131 ms 14828 KB Output is correct
29 Execution timed out 3030 ms 62060 KB Time limit exceeded
30 Halted 0 ms 0 KB -