JOISC2019Day 1試験 (Examination)
题面
题解
就是个裸的三维数点,\(CDQ\)直接套上去就行了
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
R int res,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R int x){
if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
while(z[++Z]=x%10+48,x/=10);
while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=2e5+5;
struct node{
int x,y,z,id;
inline bool operator <(const node &b)const{return z==b.z?id<b.id:z>b.z;}
}p[N],st[N];
int n,q,m,ans[N],c[N],b[N];
inline void add(R int x){for(;x<=m;x+=x&-x)++c[x];}
inline void clr(R int x){for(;x<=m;x+=x&-x)c[x]=0;}
inline int query(R int x){R int res=0;for(;x;x-=x&-x)res+=c[x];return res;}
void solve(int l,int r){
if(l==r)return;
int mid=(l+r)>>1;
solve(l,mid),solve(mid+1,r);
for(R int i=l,j=mid+1,k=l;k<=r;++k)
if(j>r||(i<=mid&&p[i].x>=p[j].x)){
st[k]=p[i++];
if(!st[k].id)add(st[k].y);
}else{
st[k]=p[j++];
if(st[k].id)ans[st[k].id]+=query(st[k].y);
}
fp(i,l,mid)if(!p[i].id)clr(p[i].y);
fp(i,l,r)p[i]=st[i];
}
int main(){
// freopen("testdata.in","r",stdin);
n=read(),q=read();
fp(i,1,n)p[i].id=0,p[i].x=read(),p[i].y=read(),p[i].z=p[i].x+p[i].y;
fp(i,1,q)p[i+n].id=i,p[i+n].x=read(),p[i+n].y=read(),p[i+n].z=read();
fp(i,1,n+q)b[++m]=p[i].y;
sort(b+1,b+1+m),m=unique(b+1,b+1+m)-b-1;
fp(i,1,n+q)p[i].y=m-(lower_bound(b+1,b+1+m,p[i].y)-b)+1;
sort(p+1,p+1+n+q),solve(1,n+q);
fp(i,1,q)print(ans[i]);
return Ot(),0;
}
深深地明白自己的弱小