This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define nl '\n'
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
const int N=1e5+11;
const int M=3e5+11;
const int W=1e3+11;
const int inf=1e9;
const ll INF=1e18;
const ll mod=1e9+7;
const ld EPS=1e-9;
struct st{
int res=0;
st *l=0,*r=0;
int tl,tr;
st(int a,int b){
tl=a,tr=b;
}
void upd(int pos,int val){
if(tl==tr){
res+=val;
return ;
}
int tm=(tl+tr)/2;
if(pos<=tm){
if(!l)l=new st(tl,tm);
l->upd(pos,val);
}
else{
if(!r)r=new st(tm+1,tr);
r->upd(pos,val);
}
res=(l?l->res:0)+(r?r->res:0);
}
int get(int a,int b){
if(tl>b||a>tr)return 0;
if(a<=tl&&tr<=b)return res;
return (l?l->get(a,b):0)+(r?r->get(a,b):0);
}
};
struct bit{
st *t[N];
bit(){
memset(t,0,sizeof(t));
}
void upd(int x,int y,int val){
for(int i=x;i<N;i=(i|(i+1))){
if(!t[i])t[i]=new st(1,N);
t[i]->upd(y,val);
}
}
int get(int x,int y){
int res=0;
for(int i=x;i>=0;i=(i&(i+1))-1){
if(!t[i])continue;
res+=t[i]->get(y,N-1);
}
return res;
}
};
bit t;
pair<pair<int,int>,int>a[N],q[N];
int b[N],c[N];
int res[N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int n,Q;
cin>>n>>Q;
vector<int>x,y,z;
for(int i=1;i<=n;i++){
cin>>a[i].x.x>>a[i].x.y;
a[i].y=i;
x.pb(a[i].x.x);
y.pb(a[i].x.y);
z.pb(a[i].x.x+a[i].x.y);
}
sort(all(x));
sort(all(y));
sort(all(z));
for(int i=1;i<=n;i++){
b[i]=low_b(all(z),a[i].x.x+a[i].x.y)-z.begin()+1;
a[i].x.x=low_b(all(x),a[i].x.x)-x.begin()+1;
a[i].x.y=low_b(all(y),a[i].x.y)-y.begin()+1;
}
sort(a+1,a+n+1);
for(int i=1;i<=Q;i++){
cin>>q[i].x.x>>q[i].x.y>>c[i];
q[i].x.x=low_b(all(x),q[i].x.x)-x.begin()+1;
q[i].x.y=low_b(all(y),q[i].x.y)-y.begin()+1;
c[i]=low_b(all(z),c[i])-z.begin()+1;
q[i].y=i;
}
sort(q+1,q+Q+1);
reverse(q+1,q+Q+1);
int j=n;
for(int i=1;i<=Q;i++){
while(j&&a[j].x.x>=q[i].x.x)t.upd(a[j].x.y,b[a[j].y],1),j--;
res[q[i].y]=t.get(N-1,c[q[i].y])-t.get(q[i].x.y-1,c[q[i].y]);
}
for(int i=1;i<=Q;i++){
cout<<res[i]<<"\n";
}
}
# | 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... |