很明显直接二维是作死的。。所以给按X点排下序,当然离线处理询问时差分的点会方便些。。
对Y坐标就用BIT维护就行。。
但由于坐标比较大,所以还要离散化= =
处理起来略麻烦但代码并不难写
1 //#include<bits/stdc++.h> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<queue> 6 #include<iostream> 7 #define inc(i,l,r) for(int i=l;i<=r;i++) 8 #define dec(i,l,r) for(int i=l;i>=r;i--) 9 #define link(x) for(edge *j=h[x];j;j=j->next) 10 #define mem(a) memset(a,0,sizeof(a)) 11 #define ll long long 12 #define succ(x) (1<<x) 13 #define lowbit(x) (x&(-x)) 14 #define NM 500000+5 15 using namespace std; 16 int read(){ 17 int x=0,f=1;char ch=getchar(); 18 while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} 19 while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); 20 return x*f; 21 } 22 struct tmp{ 23 int x,y,id,f; 24 }a[5*NM]; 25 bool cmp(tmp x,tmp y){ 26 return x.x<y.x||(x.x==y.x&&x.id<y.id); 27 } 28 int _x,_y,__x,__y,b[5*NM],c[NM],ans[NM][5],tot,n,m,_t; 29 void upd(int x,int t){ 30 for(;x<=n;x+=lowbit(x))c[x]+=t; 31 } 32 int sum(int x){ 33 int s=0; 34 for(;x;x-=lowbit(x))s+=c[x]; 35 return s; 36 } 37 int main(){ 38 freopen("data.in","r",stdin); 39 n=read();m=read(); 40 inc(i,1,n){ 41 a[++tot].x=read();a[tot].y=read();b[tot]=a[i].y; 42 } 43 inc(i,1,m){ 44 _x=read()-1;_y=read()-1;__x=read();__y=read(); 45 a[++tot].x=_x;a[tot].y=_y;b[tot]=_y;a[tot].id=i;a[tot].f=1; 46 a[++tot].x=_x;a[tot].y=__y;b[tot]=__y;a[tot].id=i;a[tot].f=2; 47 a[++tot].x=__x;a[tot].y=_y;b[tot]=_y;a[tot].id=i;a[tot].f=3; 48 a[++tot].x=__x;a[tot].y=__y;b[tot]=__y;a[tot].id=i;a[tot].f=4; 49 } 50 sort(b+1,b+tot+1); 51 _t=unique(b+1,b+tot+1)-b-1; 52 inc(i,1,tot)a[i].y=lower_bound(b+1,b+_t+1,a[i].y)-b; 53 sort(a+1,a+tot+1,cmp); 54 /* inc(i,1,tot)printf("%d ",a[i].x);printf("\n"); 55 inc(i,1,tot)printf("%d ",a[i].y);printf("\n"); 56 inc(i,1,tot)printf("%d ",a[i].id);printf("\n");*/ 57 inc(i,1,tot) 58 if(a[i].id)ans[a[i].id][a[i].f]=sum(a[i].y); 59 else upd(a[i].y,1); 60 inc(i,1,m)printf("%d\n",ans[i][1]+ans[i][4]-ans[i][2]-ans[i][3]); 61 return 0; 62 }