#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
bool cmp1(pair <int,int> a,pair <int,int> b){
return a.second>b.second;
}
bool cmp2(pair <pair <int,int>,pair <int,int> > a,pair <pair <int,int>,pair <int,int> > b){
return a.first.second>b.first.second;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n,q;
cin>>n>>q;
pair <int,int> a[n];
for (int i=0; i<n; i++) cin>>a[i].first>>a[i].second;
pair <pair <int,int>,pair <int,int> > qu[q];
for (int i=0; i<q; i++) cin>>qu[i].first.first>>qu[i].first.second>>qu[i].second.first;
for (int i=0; i<q; i++) qu[i].second.second=i;
int ans[q];
for (int i=0; i<q; i++) ans[i]=0;
{
sort(a,a+n,cmp1);
sort(qu,qu+q,cmp2);
int ptr=0;
tree <int,null_type,greater_equal <int>,rb_tree_tag,tree_order_statistics_node_update> s;
for (int i=0; i<q; i++){
if (qu[i].first.first+qu[i].first.second<qu[i].second.first) continue;
while (ptr<n&&a[ptr].second>=qu[i].first.second){
s.insert(a[ptr].first);
ptr++;
}
ans[qu[i].second.second]=s.order_of_key(qu[i].first.first-1);
}
}
{
int ptr=0;
tree <int,null_type,greater_equal <int>,rb_tree_tag,tree_order_statistics_node_update> s;
for (int i=0; i<q; i++){
if (qu[i].first.first+qu[i].first.second>=qu[i].second.first) continue;
while (ptr<n&&a[ptr].second>=qu[i].first.second){
s.insert(a[ptr].first+a[ptr].second);
ptr++;
}
ans[qu[i].second.second]+=s.order_of_key(qu[i].second.first-1);
}
}
{
sort(a,a+n);
sort(qu,qu+q);
int ptr=0;
tree <int,null_type,greater_equal <int>,rb_tree_tag,tree_order_statistics_node_update> s;
for (int i=0; i<q; i++){
if (qu[i].first.first+qu[i].first.second>=qu[i].second.first) continue;
while (ptr<n&&a[ptr].first<qu[i].first.first){
s.insert(a[ptr].first+a[ptr].second);
ptr++;
}
ans[qu[i].second.second]-=s.order_of_key(qu[i].second.first-1);
}
}
for (int i=0; i<q; i++) cout<<ans[i]<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
6 ms |
596 KB |
Output is correct |
8 |
Correct |
7 ms |
584 KB |
Output is correct |
9 |
Correct |
6 ms |
596 KB |
Output is correct |
10 |
Correct |
6 ms |
596 KB |
Output is correct |
11 |
Correct |
4 ms |
596 KB |
Output is correct |
12 |
Correct |
23 ms |
552 KB |
Output is correct |
13 |
Correct |
4 ms |
596 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
15 |
Correct |
4 ms |
596 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
5 ms |
588 KB |
Output is correct |
18 |
Correct |
4 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
176 ms |
10740 KB |
Output is correct |
2 |
Correct |
170 ms |
10672 KB |
Output is correct |
3 |
Correct |
140 ms |
10788 KB |
Output is correct |
4 |
Correct |
149 ms |
10008 KB |
Output is correct |
5 |
Correct |
139 ms |
10044 KB |
Output is correct |
6 |
Correct |
130 ms |
9292 KB |
Output is correct |
7 |
Correct |
131 ms |
10660 KB |
Output is correct |
8 |
Correct |
138 ms |
10696 KB |
Output is correct |
9 |
Correct |
187 ms |
10548 KB |
Output is correct |
10 |
Correct |
118 ms |
9792 KB |
Output is correct |
11 |
Correct |
120 ms |
9804 KB |
Output is correct |
12 |
Correct |
102 ms |
8844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
176 ms |
10740 KB |
Output is correct |
2 |
Correct |
170 ms |
10672 KB |
Output is correct |
3 |
Correct |
140 ms |
10788 KB |
Output is correct |
4 |
Correct |
149 ms |
10008 KB |
Output is correct |
5 |
Correct |
139 ms |
10044 KB |
Output is correct |
6 |
Correct |
130 ms |
9292 KB |
Output is correct |
7 |
Correct |
131 ms |
10660 KB |
Output is correct |
8 |
Correct |
138 ms |
10696 KB |
Output is correct |
9 |
Correct |
187 ms |
10548 KB |
Output is correct |
10 |
Correct |
118 ms |
9792 KB |
Output is correct |
11 |
Correct |
120 ms |
9804 KB |
Output is correct |
12 |
Correct |
102 ms |
8844 KB |
Output is correct |
13 |
Correct |
232 ms |
11112 KB |
Output is correct |
14 |
Correct |
285 ms |
11140 KB |
Output is correct |
15 |
Correct |
141 ms |
10796 KB |
Output is correct |
16 |
Correct |
230 ms |
10316 KB |
Output is correct |
17 |
Correct |
187 ms |
10352 KB |
Output is correct |
18 |
Correct |
170 ms |
9384 KB |
Output is correct |
19 |
Correct |
238 ms |
11092 KB |
Output is correct |
20 |
Correct |
464 ms |
11096 KB |
Output is correct |
21 |
Correct |
225 ms |
11160 KB |
Output is correct |
22 |
Correct |
126 ms |
9792 KB |
Output is correct |
23 |
Correct |
106 ms |
9756 KB |
Output is correct |
24 |
Correct |
110 ms |
8844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
6 ms |
596 KB |
Output is correct |
8 |
Correct |
7 ms |
584 KB |
Output is correct |
9 |
Correct |
6 ms |
596 KB |
Output is correct |
10 |
Correct |
6 ms |
596 KB |
Output is correct |
11 |
Correct |
4 ms |
596 KB |
Output is correct |
12 |
Correct |
23 ms |
552 KB |
Output is correct |
13 |
Correct |
4 ms |
596 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
15 |
Correct |
4 ms |
596 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
5 ms |
588 KB |
Output is correct |
18 |
Correct |
4 ms |
468 KB |
Output is correct |
19 |
Correct |
176 ms |
10740 KB |
Output is correct |
20 |
Correct |
170 ms |
10672 KB |
Output is correct |
21 |
Correct |
140 ms |
10788 KB |
Output is correct |
22 |
Correct |
149 ms |
10008 KB |
Output is correct |
23 |
Correct |
139 ms |
10044 KB |
Output is correct |
24 |
Correct |
130 ms |
9292 KB |
Output is correct |
25 |
Correct |
131 ms |
10660 KB |
Output is correct |
26 |
Correct |
138 ms |
10696 KB |
Output is correct |
27 |
Correct |
187 ms |
10548 KB |
Output is correct |
28 |
Correct |
118 ms |
9792 KB |
Output is correct |
29 |
Correct |
120 ms |
9804 KB |
Output is correct |
30 |
Correct |
102 ms |
8844 KB |
Output is correct |
31 |
Correct |
232 ms |
11112 KB |
Output is correct |
32 |
Correct |
285 ms |
11140 KB |
Output is correct |
33 |
Correct |
141 ms |
10796 KB |
Output is correct |
34 |
Correct |
230 ms |
10316 KB |
Output is correct |
35 |
Correct |
187 ms |
10352 KB |
Output is correct |
36 |
Correct |
170 ms |
9384 KB |
Output is correct |
37 |
Correct |
238 ms |
11092 KB |
Output is correct |
38 |
Correct |
464 ms |
11096 KB |
Output is correct |
39 |
Correct |
225 ms |
11160 KB |
Output is correct |
40 |
Correct |
126 ms |
9792 KB |
Output is correct |
41 |
Correct |
106 ms |
9756 KB |
Output is correct |
42 |
Correct |
110 ms |
8844 KB |
Output is correct |
43 |
Correct |
407 ms |
13132 KB |
Output is correct |
44 |
Correct |
283 ms |
13124 KB |
Output is correct |
45 |
Correct |
220 ms |
13092 KB |
Output is correct |
46 |
Correct |
231 ms |
11584 KB |
Output is correct |
47 |
Correct |
196 ms |
11524 KB |
Output is correct |
48 |
Correct |
166 ms |
9052 KB |
Output is correct |
49 |
Correct |
210 ms |
12948 KB |
Output is correct |
50 |
Correct |
232 ms |
13032 KB |
Output is correct |
51 |
Correct |
198 ms |
12976 KB |
Output is correct |
52 |
Correct |
188 ms |
11304 KB |
Output is correct |
53 |
Correct |
108 ms |
10636 KB |
Output is correct |