#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn=1e9*2;
struct stud
{
int a,b;
};
bool cmp(stud a1,stud a2)
{
return a1.a>a2.a;
}
struct query
{
int x,y,z,ind;
};
bool cmp2(query a1,query a2)
{
return a1.x>a2.x;
}
struct cell
{
int l,r,in;
};
struct cell2
{
int l,r,st;
};
int n,q,br=1,otg[100005],mid,q1,q2,ot;
stud a[100005];
query b[100005];
cell p[5000005];
cell2 p2[100000005];
void update2(int l,int r,int h)
{
if(l==r)
{
p2[h].st++;
return;
}
mid=l/2+r/2+(l%2+r%2)/2;
if(mid>=q2)
{
if(!p2[h].l)
{
br++;
p2[h].l=br;
}
update2(l,mid,p2[h].l);
}
else
{
if(!p2[h].r)
{
br++;
p2[h].r=br;
}
update2(mid+1,r,p2[h].r);
}
p2[h].st=p2[p2[h].l].st+p2[p2[h].r].st;
}
void update1(int l,int r,int h)
{
if(!p[h].in)
{
br++;
p[h].in=br;
}
update2(0,maxn,p[h].in);
if(l==r)return;
mid=l/2+r/2+(l%2+r%2)/2;
if(mid>=q1)
{
if(!p[h].l)
{
br++;
p[h].l=br;
}
update1(l,mid,p[h].l);
}
else
{
if(!p[h].r)
{
br++;
p[h].r=br;
}
update1(mid+1,r,p[h].r);
}
}
void sum2(int l,int r,int h)
{
if(l>=q2)
{
ot+=p2[h].st;
return;
}
mid=l/2+r/2+(l%2+r%2)/2;
if(p2[h].r)
{
sum2(mid+1,r,p2[h].r);
}
mid=l/2+r/2+(l%2+r%2)/2;
if(p2[h].l&&mid>=q2)
{
sum2(l,mid,p2[h].l);
}
}
void sum1(int l,int r,int h)
{
if(!p[h].in)return;
if(l>=q1)
{
sum2(0,maxn,p[h].in);
return;
}
mid=l/2+r/2+(l%2+r%2)/2;
if(p[h].r)sum1(mid+1,r,p[h].r);
mid=l/2+r/2+(l%2+r%2)/2;
if(p[h].l&&mid>=q1)sum1(l,mid,p[h].l);
}
void resh()
{
int pos=1;
for(int i=1;i<=n;i++)
{
while(pos<=n&&a[pos].a>=b[i].x)
{
q1=a[pos].b;
q2=a[pos].a+a[pos].b;
update1(0,maxn/2,1);
pos++;
}
q1=b[i].y;
q2=b[i].z;
ot=0;
sum1(0,maxn/2,1);
otg[b[i].ind]=ot;
}
for(int i=1;i<=q;i++)
{
cout<<otg[i]<<endl;
}
}
void read()
{
cin>>n>>q;
for(int i=1;i<=n;i++)
{
cin>>a[i].a>>a[i].b;
}
for(int i=1;i<=q;i++)
{
cin>>b[i].x>>b[i].y>>b[i].z;
b[i].ind=i;
}
sort(a+1,a+n+1,cmp);
sort(b+1,b+q+1,cmp2);
resh();
}
int main()
{
speed();
read();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |