#include<bits/stdc++.h>
using namespace std;
#define pb push_back
struct ev {
int a,b,c;
int is_q;
int id;
};
int ans[100001];
void dc2(vector<ev>& t, int L, int R) {
if(L>=R) return ;
int mid=(L+R)/2;
vector<int> lst;
for(int i=mid+1;i<=R;++i) {
if(!t[i].is_q) lst.pb(t[i].c);
}
sort(lst.begin(),lst.end());
for(int i=L;i<=mid;++i) {
if(t[i].is_q) {
auto it=lower_bound(lst.begin(), lst.end(), t[i].c);
ans[t[i].id]+=lst.end()-it;
}
}
dc2(t, L, mid);
dc2(t, mid+1, R);
}
void dc1(vector<ev>& t, int L, int R) {
if(L>=R) return ;
int mid=(L+R)/2;
vector<ev> arr;
for(int i=L;i<=mid;++i) {
if(t[i].is_q) arr.pb(t[i]);
}
for(int i=mid+1;i<=R;++i) {
if(!t[i].is_q) arr.pb(t[i]);
}
sort(arr.begin(),arr.end(), [&](ev a, ev b) -> bool {
if(a.b==b.b) return a.is_q>b.is_q;
return a.b<b.b;
});
dc2(arr, 0, (int)arr.size()-1);
dc1(t, L, mid);
dc1(t, mid+1, R);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,q;
cin>>n>>q;
vector<ev> lst;
for(int i=0;i<n;++i) {
int a,b;
cin>>a>>b;
lst.push_back({a,b,a+b,0,-1});
}
for(int i=0;i<q;++i) {
int a,b,c;
cin>>a>>b>>c;
lst.push_back({a,b,c,1,i});
}
sort(lst.begin(), lst.end(), [&](ev a, ev b) -> bool {
if(a.a==b.a) return a.is_q>b.is_q;
return a.a<b.a;
});
dc1(lst, 0, (int)lst.size()-1);
for(int i=0;i<q;++i) cout<<ans[i]<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
248 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
16 ms |
680 KB |
Output is correct |
8 |
Correct |
16 ms |
728 KB |
Output is correct |
9 |
Correct |
17 ms |
632 KB |
Output is correct |
10 |
Correct |
15 ms |
632 KB |
Output is correct |
11 |
Correct |
14 ms |
632 KB |
Output is correct |
12 |
Correct |
13 ms |
632 KB |
Output is correct |
13 |
Correct |
15 ms |
676 KB |
Output is correct |
14 |
Correct |
16 ms |
632 KB |
Output is correct |
15 |
Correct |
15 ms |
632 KB |
Output is correct |
16 |
Correct |
12 ms |
728 KB |
Output is correct |
17 |
Correct |
13 ms |
632 KB |
Output is correct |
18 |
Correct |
10 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
554 ms |
9432 KB |
Output is correct |
2 |
Correct |
554 ms |
9376 KB |
Output is correct |
3 |
Correct |
549 ms |
9308 KB |
Output is correct |
4 |
Correct |
464 ms |
9308 KB |
Output is correct |
5 |
Correct |
399 ms |
9820 KB |
Output is correct |
6 |
Correct |
313 ms |
9688 KB |
Output is correct |
7 |
Correct |
506 ms |
11996 KB |
Output is correct |
8 |
Correct |
481 ms |
9304 KB |
Output is correct |
9 |
Correct |
470 ms |
11996 KB |
Output is correct |
10 |
Correct |
346 ms |
11100 KB |
Output is correct |
11 |
Correct |
378 ms |
9436 KB |
Output is correct |
12 |
Correct |
250 ms |
9688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
554 ms |
9432 KB |
Output is correct |
2 |
Correct |
554 ms |
9376 KB |
Output is correct |
3 |
Correct |
549 ms |
9308 KB |
Output is correct |
4 |
Correct |
464 ms |
9308 KB |
Output is correct |
5 |
Correct |
399 ms |
9820 KB |
Output is correct |
6 |
Correct |
313 ms |
9688 KB |
Output is correct |
7 |
Correct |
506 ms |
11996 KB |
Output is correct |
8 |
Correct |
481 ms |
9304 KB |
Output is correct |
9 |
Correct |
470 ms |
11996 KB |
Output is correct |
10 |
Correct |
346 ms |
11100 KB |
Output is correct |
11 |
Correct |
378 ms |
9436 KB |
Output is correct |
12 |
Correct |
250 ms |
9688 KB |
Output is correct |
13 |
Correct |
611 ms |
9308 KB |
Output is correct |
14 |
Correct |
572 ms |
9436 KB |
Output is correct |
15 |
Correct |
555 ms |
9688 KB |
Output is correct |
16 |
Correct |
502 ms |
9284 KB |
Output is correct |
17 |
Correct |
435 ms |
9944 KB |
Output is correct |
18 |
Correct |
320 ms |
9688 KB |
Output is correct |
19 |
Correct |
589 ms |
9564 KB |
Output is correct |
20 |
Correct |
592 ms |
9412 KB |
Output is correct |
21 |
Correct |
582 ms |
11992 KB |
Output is correct |
22 |
Correct |
366 ms |
11224 KB |
Output is correct |
23 |
Correct |
384 ms |
9436 KB |
Output is correct |
24 |
Correct |
254 ms |
9308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
248 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
16 ms |
680 KB |
Output is correct |
8 |
Correct |
16 ms |
728 KB |
Output is correct |
9 |
Correct |
17 ms |
632 KB |
Output is correct |
10 |
Correct |
15 ms |
632 KB |
Output is correct |
11 |
Correct |
14 ms |
632 KB |
Output is correct |
12 |
Correct |
13 ms |
632 KB |
Output is correct |
13 |
Correct |
15 ms |
676 KB |
Output is correct |
14 |
Correct |
16 ms |
632 KB |
Output is correct |
15 |
Correct |
15 ms |
632 KB |
Output is correct |
16 |
Correct |
12 ms |
728 KB |
Output is correct |
17 |
Correct |
13 ms |
632 KB |
Output is correct |
18 |
Correct |
10 ms |
632 KB |
Output is correct |
19 |
Correct |
554 ms |
9432 KB |
Output is correct |
20 |
Correct |
554 ms |
9376 KB |
Output is correct |
21 |
Correct |
549 ms |
9308 KB |
Output is correct |
22 |
Correct |
464 ms |
9308 KB |
Output is correct |
23 |
Correct |
399 ms |
9820 KB |
Output is correct |
24 |
Correct |
313 ms |
9688 KB |
Output is correct |
25 |
Correct |
506 ms |
11996 KB |
Output is correct |
26 |
Correct |
481 ms |
9304 KB |
Output is correct |
27 |
Correct |
470 ms |
11996 KB |
Output is correct |
28 |
Correct |
346 ms |
11100 KB |
Output is correct |
29 |
Correct |
378 ms |
9436 KB |
Output is correct |
30 |
Correct |
250 ms |
9688 KB |
Output is correct |
31 |
Correct |
611 ms |
9308 KB |
Output is correct |
32 |
Correct |
572 ms |
9436 KB |
Output is correct |
33 |
Correct |
555 ms |
9688 KB |
Output is correct |
34 |
Correct |
502 ms |
9284 KB |
Output is correct |
35 |
Correct |
435 ms |
9944 KB |
Output is correct |
36 |
Correct |
320 ms |
9688 KB |
Output is correct |
37 |
Correct |
589 ms |
9564 KB |
Output is correct |
38 |
Correct |
592 ms |
9412 KB |
Output is correct |
39 |
Correct |
582 ms |
11992 KB |
Output is correct |
40 |
Correct |
366 ms |
11224 KB |
Output is correct |
41 |
Correct |
384 ms |
9436 KB |
Output is correct |
42 |
Correct |
254 ms |
9308 KB |
Output is correct |
43 |
Correct |
611 ms |
9512 KB |
Output is correct |
44 |
Correct |
615 ms |
9432 KB |
Output is correct |
45 |
Correct |
573 ms |
9560 KB |
Output is correct |
46 |
Correct |
512 ms |
9176 KB |
Output is correct |
47 |
Correct |
444 ms |
9820 KB |
Output is correct |
48 |
Correct |
334 ms |
9816 KB |
Output is correct |
49 |
Correct |
572 ms |
11992 KB |
Output is correct |
50 |
Correct |
548 ms |
9308 KB |
Output is correct |
51 |
Correct |
558 ms |
11992 KB |
Output is correct |
52 |
Correct |
370 ms |
11096 KB |
Output is correct |
53 |
Correct |
381 ms |
9564 KB |
Output is correct |