#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb emplace_back
#define all(n) (n).begin(),(n).end()
#define mem(n,x) memset(n,x,sizeof(n))
#define IOS ios::sync_with_stdio(0),cin.tie(0)
#define pii pair<ll,ll>
#define vi vector<ll>
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);
template<typename A> void _do(A x){ cerr<<x<<"\n"; }
template<typename A, typename ...B> void _do(A x, B ...y){ cerr<<x<<", "; _do(y...);}
int N, Q, ans[200005];
struct point{
int x, y, z, id;
} arr[200005];
bool xcmp(point &a, point &b){
if(a.x != b.x) return a.x > b.x;
if(a.y != b.y) return a.y > b.y;
if(a.z != b.z) return a.z > b.z;
return a.id < b.id;
}
bool ycmp(point &a, point &b){
if(a.y != b.y) return a.y > b.y;
if(a.z != b.z) return a.z > b.z;
return a.id < b.id;
}
int bit[200005];
void add(int x, int v){
for(;x<=N+Q;x+=x&-x) bit[x] += v;
}
int query(int x){
int ans = 0;
for(;x;x-=x&-x) ans += bit[x];
return ans;
}
void solve(int l, int r){
if(l == r) return;
int m = (l+r) / 2;
solve(l, m);
solve(m+1, r);
sort(arr+l, arr+m+1, ycmp);
sort(arr+m+1, arr+r+1, ycmp);
int idx = l;
for(int i=m+1;i<=r;i++){
while(idx <= m && arr[idx].y >= arr[i].y){
if(!arr[idx].id) add(arr[idx].z, 1);
idx++;
}
if(arr[i].id) ans[arr[i].id] += query(N+Q) - query(arr[i].z - 1);
}
for(int i=l;i<idx;i++) if(!arr[i].id) add(arr[i].z, -1);
}
signed main(){
IOS;
cin >> N >> Q;
for(int i=1;i<=N;i++) cin >> arr[i].x >> arr[i].y, arr[i].z = arr[i].x + arr[i].y, arr[i].id=0;
for(int i=1;i<=Q;i++) cin >> arr[i+N].x >> arr[i+N].y >> arr[i+N].z, arr[i+N].id = i;
vector<int> ax, ay, az;
for(int i=1;i<=N+Q;i++) ax.pb(arr[i].x), ay.pb(arr[i].y), az.pb(arr[i].z);
sort(all(ax)), sort(all(ay)), sort(all(az));
ax.resize(unique(all(ax))-ax.begin());
ay.resize(unique(all(ay))-ay.begin());
az.resize(unique(all(az))-az.begin());
for(int i=1;i<=N+Q;i++){
arr[i].x = lower_bound(all(ax), arr[i].x) - ax.begin() + 1;
arr[i].y = lower_bound(all(ay), arr[i].y) - ay.begin() + 1;
arr[i].z = lower_bound(all(az), arr[i].z) - az.begin() + 1;
}
sort(arr+1, arr+1+N+Q, xcmp);
solve(1, N+Q);
for(int i=1;i<=Q;i++) cout << ans[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
12 ms |
748 KB |
Output is correct |
8 |
Correct |
12 ms |
748 KB |
Output is correct |
9 |
Correct |
12 ms |
748 KB |
Output is correct |
10 |
Correct |
11 ms |
748 KB |
Output is correct |
11 |
Correct |
10 ms |
748 KB |
Output is correct |
12 |
Correct |
10 ms |
620 KB |
Output is correct |
13 |
Correct |
11 ms |
748 KB |
Output is correct |
14 |
Correct |
11 ms |
768 KB |
Output is correct |
15 |
Correct |
11 ms |
748 KB |
Output is correct |
16 |
Correct |
8 ms |
748 KB |
Output is correct |
17 |
Correct |
10 ms |
748 KB |
Output is correct |
18 |
Correct |
6 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
602 ms |
9704 KB |
Output is correct |
2 |
Correct |
553 ms |
9684 KB |
Output is correct |
3 |
Correct |
575 ms |
9684 KB |
Output is correct |
4 |
Correct |
482 ms |
9104 KB |
Output is correct |
5 |
Correct |
423 ms |
8916 KB |
Output is correct |
6 |
Correct |
314 ms |
8020 KB |
Output is correct |
7 |
Correct |
534 ms |
9812 KB |
Output is correct |
8 |
Correct |
545 ms |
10068 KB |
Output is correct |
9 |
Correct |
529 ms |
9684 KB |
Output is correct |
10 |
Correct |
401 ms |
8832 KB |
Output is correct |
11 |
Correct |
493 ms |
8780 KB |
Output is correct |
12 |
Correct |
266 ms |
7636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
602 ms |
9704 KB |
Output is correct |
2 |
Correct |
553 ms |
9684 KB |
Output is correct |
3 |
Correct |
575 ms |
9684 KB |
Output is correct |
4 |
Correct |
482 ms |
9104 KB |
Output is correct |
5 |
Correct |
423 ms |
8916 KB |
Output is correct |
6 |
Correct |
314 ms |
8020 KB |
Output is correct |
7 |
Correct |
534 ms |
9812 KB |
Output is correct |
8 |
Correct |
545 ms |
10068 KB |
Output is correct |
9 |
Correct |
529 ms |
9684 KB |
Output is correct |
10 |
Correct |
401 ms |
8832 KB |
Output is correct |
11 |
Correct |
493 ms |
8780 KB |
Output is correct |
12 |
Correct |
266 ms |
7636 KB |
Output is correct |
13 |
Correct |
607 ms |
10452 KB |
Output is correct |
14 |
Correct |
597 ms |
10324 KB |
Output is correct |
15 |
Correct |
554 ms |
9940 KB |
Output is correct |
16 |
Correct |
559 ms |
9428 KB |
Output is correct |
17 |
Correct |
454 ms |
9556 KB |
Output is correct |
18 |
Correct |
312 ms |
8020 KB |
Output is correct |
19 |
Correct |
604 ms |
10460 KB |
Output is correct |
20 |
Correct |
610 ms |
10296 KB |
Output is correct |
21 |
Correct |
578 ms |
10452 KB |
Output is correct |
22 |
Correct |
369 ms |
9048 KB |
Output is correct |
23 |
Correct |
488 ms |
8916 KB |
Output is correct |
24 |
Correct |
278 ms |
7636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
12 ms |
748 KB |
Output is correct |
8 |
Correct |
12 ms |
748 KB |
Output is correct |
9 |
Correct |
12 ms |
748 KB |
Output is correct |
10 |
Correct |
11 ms |
748 KB |
Output is correct |
11 |
Correct |
10 ms |
748 KB |
Output is correct |
12 |
Correct |
10 ms |
620 KB |
Output is correct |
13 |
Correct |
11 ms |
748 KB |
Output is correct |
14 |
Correct |
11 ms |
768 KB |
Output is correct |
15 |
Correct |
11 ms |
748 KB |
Output is correct |
16 |
Correct |
8 ms |
748 KB |
Output is correct |
17 |
Correct |
10 ms |
748 KB |
Output is correct |
18 |
Correct |
6 ms |
620 KB |
Output is correct |
19 |
Correct |
602 ms |
9704 KB |
Output is correct |
20 |
Correct |
553 ms |
9684 KB |
Output is correct |
21 |
Correct |
575 ms |
9684 KB |
Output is correct |
22 |
Correct |
482 ms |
9104 KB |
Output is correct |
23 |
Correct |
423 ms |
8916 KB |
Output is correct |
24 |
Correct |
314 ms |
8020 KB |
Output is correct |
25 |
Correct |
534 ms |
9812 KB |
Output is correct |
26 |
Correct |
545 ms |
10068 KB |
Output is correct |
27 |
Correct |
529 ms |
9684 KB |
Output is correct |
28 |
Correct |
401 ms |
8832 KB |
Output is correct |
29 |
Correct |
493 ms |
8780 KB |
Output is correct |
30 |
Correct |
266 ms |
7636 KB |
Output is correct |
31 |
Correct |
607 ms |
10452 KB |
Output is correct |
32 |
Correct |
597 ms |
10324 KB |
Output is correct |
33 |
Correct |
554 ms |
9940 KB |
Output is correct |
34 |
Correct |
559 ms |
9428 KB |
Output is correct |
35 |
Correct |
454 ms |
9556 KB |
Output is correct |
36 |
Correct |
312 ms |
8020 KB |
Output is correct |
37 |
Correct |
604 ms |
10460 KB |
Output is correct |
38 |
Correct |
610 ms |
10296 KB |
Output is correct |
39 |
Correct |
578 ms |
10452 KB |
Output is correct |
40 |
Correct |
369 ms |
9048 KB |
Output is correct |
41 |
Correct |
488 ms |
8916 KB |
Output is correct |
42 |
Correct |
278 ms |
7636 KB |
Output is correct |
43 |
Correct |
623 ms |
12628 KB |
Output is correct |
44 |
Correct |
618 ms |
12540 KB |
Output is correct |
45 |
Correct |
609 ms |
12628 KB |
Output is correct |
46 |
Correct |
556 ms |
11092 KB |
Output is correct |
47 |
Correct |
464 ms |
10964 KB |
Output is correct |
48 |
Correct |
336 ms |
7892 KB |
Output is correct |
49 |
Correct |
634 ms |
12600 KB |
Output is correct |
50 |
Correct |
602 ms |
12484 KB |
Output is correct |
51 |
Correct |
600 ms |
12372 KB |
Output is correct |
52 |
Correct |
392 ms |
10964 KB |
Output is correct |
53 |
Correct |
489 ms |
9684 KB |
Output is correct |