#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define N 500003 using namespace std; int n,m,b[N*5],a[N*5],ans1[N][10]; int x[N],y[N],cnt1,cnt2; int f[N],sz; struct data { int x,y,x1,y1,p; };data ans[N]; struct node { int x,y; };node pos[N]; struct tr { int x,y,id,v; };tr q[N*5]; int cmp3(tr a,tr b) { return a.x<b.x||a.x==b.x&&a.id<b.id; } int lowbit(int x) { return x&(-x); } void change(int x,int v) { for (int i=x;i<=cnt2;i+=lowbit(i)) f[i]+=v; } int sum(int x) { int ans=0; for (int i=x;i>=1;i-=lowbit(i)) ans+=f[i]; return ans; } int main() { scanf("%d%d",&n,&m); cnt1=n; cnt2=n; for (int i=1;i<=n;i++) { scanf("%d%d",&a[i],&b[i]); pos[i].x=a[i]; pos[i].y=b[i]; } for (int i=1;i<=m;i++) { scanf("%d%d%d%d",&ans[i].x,&ans[i].y,&ans[i].x1,&ans[i].y1); a[++cnt1]=ans[i].x; a[++cnt1]=ans[i].x1; b[++cnt2]=ans[i].y; b[++cnt2]=ans[i].y1; ans[i].p=i; } sort(a+1,a+cnt1+1); sort(b+1,b+cnt2+1); cnt1=unique(a+1,a+cnt1+1)-a-1; cnt2=unique(b+1,b+cnt2+1)-b-1; for (int i=1;i<=n;i++) { pos[i].x=lower_bound(a+1,a+cnt1+1,pos[i].x)-a; pos[i].y=lower_bound(b+1,b+cnt2+1,pos[i].y)-b; q[++sz].x=pos[i].x; q[sz].y=pos[i].y; } for (int i=1;i<=m;i++) { ans[i].x=lower_bound(a+1,a+cnt1+1,ans[i].x)-a; ans[i].x1=lower_bound(a+1,a+cnt1+1,ans[i].x1)-a; ans[i].y=lower_bound(b+1,b+cnt2+1,ans[i].y)-b; ans[i].y1=lower_bound(b+1,b+cnt2+1,ans[i].y1)-b; } for (int i=1;i<=m;i++) { q[++sz].x=ans[i].x-1; q[sz].y=ans[i].y-1; q[sz].id=i; q[sz].v=1; q[++sz].x=ans[i].x-1; q[sz].y=ans[i].y1; q[sz].id=i; q[sz].v=2; q[++sz].x=ans[i].x1; q[sz].y=ans[i].y-1; q[sz].id=i; q[sz].v=3; q[++sz].x=ans[i].x1; q[sz].y=ans[i].y1; q[sz].id=i; q[sz].v=4; } sort(q+1,q+sz+1,cmp3); for (int i=1;i<=sz;i++) { if (!q[i].id) change(q[i].y,1); else ans1[q[i].id][q[i].v]=sum(q[i].y); } for (int i=1;i<=m;i++) printf("%d\n",ans1[i][4]+ans1[i][1]-ans1[i][2]-ans1[i][3]); }