#include<bits/stdc++.h>
using ll = long long;
using namespace std;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL << (i))
const ll MAXN = 1e5+100;
const ll INF = 1e18;
ll dp[MAXN];
ll n,q;
pll a[MAXN];
vector <ll> tree1[MAXN*4],tree2[MAXN*4];
vector <ll> val;
void update(ll id,ll l,ll r,ll pos){
if (val[l] > a[pos].fi || val[r] < a[pos].fi)return;
tree1[id].push_back(a[pos].se);
tree2[id].push_back(a[pos].fi + a[pos].se);
if (l == r){
return;
}
ll mid = (l + r) >> 1;
update(id<<1,l,mid,pos);
update(id<<1|1,mid+1,r,pos);
}
void build(ll id,ll l,ll r){
sort(tree1[id].begin(),tree1[id].end());
sort(tree2[id].begin(),tree2[id].end());
// cout<<id<<' '<<l<<' '<<r<<'\n';
// cout<<"tree1 : ";for (auto x:tree1[id])cout<<x<<' ';cout<<'\n';
// cout<<"tree2 : ";for (auto x:tree2[id])cout<<x<<' ';cout<<'\n';
if (l != r){
ll mid = (l + r) >> 1;
build(id<<1,l,mid);
build(id<<1|1,mid+1,r);
}
}
vector <ll> all;
ll get1(ll id,ll l,ll r,ll l1, ll B){
if (val[r] < l1)return 0;
if (val[l] >= l1){
return tree1[id].end() - lower_bound(tree1[id].begin(),tree1[id].end(),B);
}
ll mid = (l + r) >> 1;
return get1(id<<1,l,mid,l1,B) + get1(id<<1|1,mid+1,r,l1,B);
}
ll get2(ll id,ll l,ll r,ll l1,ll r1,ll C){
if (val[l] > r1 || l1 > val[r] || l1 > r1)return 0;
if (l1 <= val[l] && val[r] <= r1){
return tree2[id].end() - lower_bound(tree2[id].begin(),tree2[id].end(),C);;
}
ll mid = (l + r) >> 1;
return get2(id<<1,l,mid,l1,r1,C) + get2(id<<1|1,mid+1,r,l1,r1,C);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(nullptr);
cin>>n>>q;
for (ll i = 1;i <= n;i ++){
cin>>a[i].fi>>a[i].se;
val.push_back(a[i].fi);
}
sort(val.begin(),val.end());
val.resize(unique(val.begin(),val.end())-val.begin());
val.insert(val.begin(),0);
// cout<<"WOW "<<sz(val)<<endl;
for (ll i = 1;i <= n;i ++){
update(1,1,sz(val)-1,i);
}
build(1,1,sz(val)-1);
while (q--){
ll A,B,C;
cin>>A>>B>>C;
ll tmp = max(A,C-B);
cout<<get1(1,1,sz(val)-1,tmp,B)+get2(1,1,sz(val)-1,A,tmp-1,C)<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
21080 KB |
Output is correct |
2 |
Correct |
2 ms |
21084 KB |
Output is correct |
3 |
Correct |
2 ms |
21084 KB |
Output is correct |
4 |
Correct |
2 ms |
21084 KB |
Output is correct |
5 |
Correct |
2 ms |
21084 KB |
Output is correct |
6 |
Correct |
2 ms |
21084 KB |
Output is correct |
7 |
Correct |
8 ms |
22200 KB |
Output is correct |
8 |
Correct |
8 ms |
22108 KB |
Output is correct |
9 |
Correct |
8 ms |
22108 KB |
Output is correct |
10 |
Correct |
8 ms |
22108 KB |
Output is correct |
11 |
Correct |
5 ms |
21336 KB |
Output is correct |
12 |
Correct |
4 ms |
21340 KB |
Output is correct |
13 |
Correct |
8 ms |
22108 KB |
Output is correct |
14 |
Correct |
7 ms |
22088 KB |
Output is correct |
15 |
Correct |
8 ms |
22108 KB |
Output is correct |
16 |
Correct |
4 ms |
21084 KB |
Output is correct |
17 |
Correct |
7 ms |
22108 KB |
Output is correct |
18 |
Correct |
4 ms |
21080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
286 ms |
59636 KB |
Output is correct |
2 |
Correct |
289 ms |
59588 KB |
Output is correct |
3 |
Correct |
280 ms |
59852 KB |
Output is correct |
4 |
Correct |
231 ms |
59600 KB |
Output is correct |
5 |
Correct |
94 ms |
31996 KB |
Output is correct |
6 |
Correct |
53 ms |
32204 KB |
Output is correct |
7 |
Correct |
272 ms |
59596 KB |
Output is correct |
8 |
Correct |
255 ms |
59564 KB |
Output is correct |
9 |
Correct |
241 ms |
59708 KB |
Output is correct |
10 |
Correct |
40 ms |
24280 KB |
Output is correct |
11 |
Correct |
195 ms |
59596 KB |
Output is correct |
12 |
Correct |
24 ms |
24280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
286 ms |
59636 KB |
Output is correct |
2 |
Correct |
289 ms |
59588 KB |
Output is correct |
3 |
Correct |
280 ms |
59852 KB |
Output is correct |
4 |
Correct |
231 ms |
59600 KB |
Output is correct |
5 |
Correct |
94 ms |
31996 KB |
Output is correct |
6 |
Correct |
53 ms |
32204 KB |
Output is correct |
7 |
Correct |
272 ms |
59596 KB |
Output is correct |
8 |
Correct |
255 ms |
59564 KB |
Output is correct |
9 |
Correct |
241 ms |
59708 KB |
Output is correct |
10 |
Correct |
40 ms |
24280 KB |
Output is correct |
11 |
Correct |
195 ms |
59596 KB |
Output is correct |
12 |
Correct |
24 ms |
24280 KB |
Output is correct |
13 |
Correct |
323 ms |
59752 KB |
Output is correct |
14 |
Correct |
308 ms |
59596 KB |
Output is correct |
15 |
Correct |
269 ms |
59596 KB |
Output is correct |
16 |
Correct |
290 ms |
59652 KB |
Output is correct |
17 |
Correct |
98 ms |
31948 KB |
Output is correct |
18 |
Correct |
54 ms |
32104 KB |
Output is correct |
19 |
Correct |
317 ms |
59592 KB |
Output is correct |
20 |
Correct |
341 ms |
59592 KB |
Output is correct |
21 |
Correct |
329 ms |
59824 KB |
Output is correct |
22 |
Correct |
41 ms |
24276 KB |
Output is correct |
23 |
Correct |
193 ms |
59592 KB |
Output is correct |
24 |
Correct |
24 ms |
24280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
21080 KB |
Output is correct |
2 |
Correct |
2 ms |
21084 KB |
Output is correct |
3 |
Correct |
2 ms |
21084 KB |
Output is correct |
4 |
Correct |
2 ms |
21084 KB |
Output is correct |
5 |
Correct |
2 ms |
21084 KB |
Output is correct |
6 |
Correct |
2 ms |
21084 KB |
Output is correct |
7 |
Correct |
8 ms |
22200 KB |
Output is correct |
8 |
Correct |
8 ms |
22108 KB |
Output is correct |
9 |
Correct |
8 ms |
22108 KB |
Output is correct |
10 |
Correct |
8 ms |
22108 KB |
Output is correct |
11 |
Correct |
5 ms |
21336 KB |
Output is correct |
12 |
Correct |
4 ms |
21340 KB |
Output is correct |
13 |
Correct |
8 ms |
22108 KB |
Output is correct |
14 |
Correct |
7 ms |
22088 KB |
Output is correct |
15 |
Correct |
8 ms |
22108 KB |
Output is correct |
16 |
Correct |
4 ms |
21084 KB |
Output is correct |
17 |
Correct |
7 ms |
22108 KB |
Output is correct |
18 |
Correct |
4 ms |
21080 KB |
Output is correct |
19 |
Correct |
286 ms |
59636 KB |
Output is correct |
20 |
Correct |
289 ms |
59588 KB |
Output is correct |
21 |
Correct |
280 ms |
59852 KB |
Output is correct |
22 |
Correct |
231 ms |
59600 KB |
Output is correct |
23 |
Correct |
94 ms |
31996 KB |
Output is correct |
24 |
Correct |
53 ms |
32204 KB |
Output is correct |
25 |
Correct |
272 ms |
59596 KB |
Output is correct |
26 |
Correct |
255 ms |
59564 KB |
Output is correct |
27 |
Correct |
241 ms |
59708 KB |
Output is correct |
28 |
Correct |
40 ms |
24280 KB |
Output is correct |
29 |
Correct |
195 ms |
59596 KB |
Output is correct |
30 |
Correct |
24 ms |
24280 KB |
Output is correct |
31 |
Correct |
323 ms |
59752 KB |
Output is correct |
32 |
Correct |
308 ms |
59596 KB |
Output is correct |
33 |
Correct |
269 ms |
59596 KB |
Output is correct |
34 |
Correct |
290 ms |
59652 KB |
Output is correct |
35 |
Correct |
98 ms |
31948 KB |
Output is correct |
36 |
Correct |
54 ms |
32104 KB |
Output is correct |
37 |
Correct |
317 ms |
59592 KB |
Output is correct |
38 |
Correct |
341 ms |
59592 KB |
Output is correct |
39 |
Correct |
329 ms |
59824 KB |
Output is correct |
40 |
Correct |
41 ms |
24276 KB |
Output is correct |
41 |
Correct |
193 ms |
59592 KB |
Output is correct |
42 |
Correct |
24 ms |
24280 KB |
Output is correct |
43 |
Correct |
369 ms |
64056 KB |
Output is correct |
44 |
Correct |
358 ms |
63948 KB |
Output is correct |
45 |
Correct |
354 ms |
63948 KB |
Output is correct |
46 |
Correct |
331 ms |
63952 KB |
Output is correct |
47 |
Correct |
111 ms |
32064 KB |
Output is correct |
48 |
Correct |
54 ms |
31812 KB |
Output is correct |
49 |
Correct |
387 ms |
63932 KB |
Output is correct |
50 |
Correct |
352 ms |
63952 KB |
Output is correct |
51 |
Correct |
428 ms |
64208 KB |
Output is correct |
52 |
Correct |
52 ms |
24276 KB |
Output is correct |
53 |
Correct |
236 ms |
63712 KB |
Output is correct |