Submission #102702

# Submission time Handle Problem Language Result Execution time Memory
102702 2019-03-27T03:11:44 Z LittleFlowers__ Examination (JOI19_examination) C++14
0 / 100
739 ms 49732 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,t;
struct id{
    int x,y,z,i;
}a[N],q[N];

int ans[N];
vector<int> rx,ry;

int upp(int x,const vector<int>&v){
    return lower_bound(all(v),x)-v.begin()+1;
}

struct IT2D{
    vector<int> val[N*4],bit[N*4];
    void build(int s,int l,int r){
        val[s].resize(r-l+1); bit[s].resize(r-l+3);
        forinc(i,l,r) val[s][i-l]=a[i].y;
        sort(all(val[s]));
        if(l==r) return;
        int m=(l+r)/2;
        build(2*s,l,m); build(2*s+1,m+1,r);
    }
    void upd(int s,int x){
        x=upp(x+1,val[s])-1;
        for(;x;x-=x&-x)
            bit[s][x]++;
    }
    void add(int s,int l,int r,int u,int x){
        upd(s,x);
        if(l==r) return;
        int m=(l+r)/2;
        if(u<=m) add(2*s,l,m,u,x);
        else     add(2*s+1,m+1,r,u,x);
    }
    int que(int s,int x){
        x=upp(x,val[s]);
        int ret=0;
        for(;x<=val[s].size();x+=x&-x)
            ret+=bit[s][x];
        return ret;
    }
    int get(int s,int l,int r,int u,int v,int x){
        if(u>v) return 0;
        if(l==u && r==v){
            return que(s,x);
        }
        int m=(l+r)/2,ret=0;
        if(u<=m) ret+=get(2*s,l,m,u,min(m,v),x);
        if(v>m)  ret+=get(2*s+1,m+1,r,max(m+1,u),v,x);
        return ret;
    }

}T;
int main(){
    ios_base::sync_with_stdio(false),cin.tie(nullptr);
    //freopen("EXAMiNATION.inp","r",stdin);
    n=in,t=in;
    forinc(i,1,n){
        int x,y; x=in,y=in; a[i]={x,y,x+y,i};
        rx.pb(a[i].x); ry.pb(a[i].y);
    }
    forinc(i,1,t) q[i]={in,in,in,i};

    sort(all(rx)); rx.erase(unique(all(rx)),rx.end());
    sort(all(ry)); ry.erase(unique(all(ry)),ry.end());

    forinc(i,1,n){
        a[i].x=upp(a[i].x,rx); a[i].y=upp(a[i].y,ry);
    }
    forinc(i,1,t){
        q[i].x=upp(q[i].x,rx); q[i].y=upp(q[i].y,ry);
    }



    sort(a+1,a+n+1,[](id i,id j){return i.x<j.x;});
    T.build(1,1,n);
    sort(a+1,a+n+1,[](id i,id j){return i.z>j.z;});
    sort(q+1,q+t+1,[](id i,id j){return i.z>j.z;});




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

Compilation message

examination.cpp: In member function 'int IT2D::que(int, int)':
examination.cpp:60:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(;x<=val[s].size();x+=x&-x)
              ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 22 ms 19200 KB Output is correct
2 Incorrect 20 ms 19128 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 739 ms 49732 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 739 ms 49732 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 19200 KB Output is correct
2 Incorrect 20 ms 19128 KB Output isn't correct
3 Halted 0 ms 0 KB -