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>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace __gnu_pbds;
using namespace std;
#define ordered_set tree< pair <int,int> , null_type, less_equal< pair <int,int> >, rb_tree_tag, tree_order_statistics_node_update>
const int N=2e5+5;
ordered_set t[N*4];
void update(int v,int tl,int tr,int ind,int val,int pos){
if(ind<tl or tr<ind)return;
if(tl==tr){
t[v].insert({val,pos});
}
else{
t[v].insert({val,pos});
int tm=(tl+tr)/2;
update(v*2,tl,tm,ind,val,pos);
update(v*2+1,tm+1,tr,ind,val,pos);
}
}
int get(int v,int tl,int tr,int l,int r,int val){
if(r<tl or tr<l)return 0;
if(l<=tl && tr<=r){
return t[v].size()-t[v].order_of_key({val,0});
}
int tm=(tl+tr)/2;
return get(v*2,tl,tm,l,r,val)+get(v*2+1,tm+1,tr,l,r,val);
}
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,q;
cin>>n>>q;
vector <pair <int,int> >v(n);
vector <int> uni;
for(int i=0;i<n;i++){
cin>>v[i].ff>>v[i].ss;
uni.pb(v[i].ss);
}
vector <vector <int> > qu;
for(int i=0;i<q;i++){
int x,y,z;
cin>>x>>y>>z;
qu.pb({x,y,z,i});
uni.pb(y);
}
sort(all(qu));reverse(all(qu));
sort(all(v));reverse(all(v));
sort(all(uni));
int cnt=0,p=-1;
map <int,int> val_ind;
for(int i=0;i<uni.size();i++){
if(uni[i]!=p){
cnt++;
val_ind[uni[i]]=cnt;
}
p=uni[i];
}
vector <int> ans(q);
int pos=0;
for(int i=0;i<q;i++){
while(pos<n && v[pos].ff>=qu[i][0]){
update(1,1,cnt,val_ind[v[pos].ss],v[pos].ff+v[pos].ss,pos);
pos++;
}
ans[qu[i][3]]=get(1,1,cnt,val_ind[qu[i][1]],cnt,qu[i][2]);
}
for(auto x : ans)cout<<x<<"\n";
}
/*
5 4
35 100
70 70
45 15
80 40
20 95
20 50 120
10 10 100
60 60 80
0 100 100
*/
Compilation message (stderr)
examination.cpp: In function 'int main()':
examination.cpp:57:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int i=0;i<uni.size();i++){
| ~^~~~~~~~~~~
# | 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... |