#include<bits/stdc++.h>
using namespace std;
int m,n;
struct node
{
int s;
int e;
};
node a[100010];
node b[100010];
int cmp(node c,node d)
{
if(c.e==d.e) return c.s<d.s;
return c.e<d.e;
}
int search(node b)
{
int left=1,right=m,mid=0;
while(left<right)
{
mid=(left+right)/2;
if(a[mid].e==b.e) return mid;
else if(a[mid].e>b.e) right=mid-1;
else left=mid+1;
}
return mid;
}
int main()
{
while(cin>>m>>n)
{
for(int i=1;i<=m;i++)
{
cin>>a[i].s>>a[i].e;
}
sort(a+1,a+1+m,cmp);
for(int i=1;i<=n;i++)
{
int ras=0;
cin>>b[i].s>>b[i].e;
int t=search(b[i]);
for(int j=1;j<=t+1;j++)
{
if(a[j].s>=b[i].s&&a[j].e<=b[i].e)
{
ras++;
b[i].s=a[j].e;
}
}
cout<<ras<<endl;
}
}
}
11-25
411
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)