#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(a) begin(a),end(a)
const int mxN = (int)6e5+10;
int n, q, fen[mxN], ans[mxN/6];
struct Query2{ int y, z, i, t; };
struct Query{ int x, y, z, i, t; };
vector<Query> A;
void upd(int x, int v){ for(; x<mxN; x+=x&-x) fen[x]+=v; }
int sum(int x){ int s=0;for(; x; x-=x&-x) s+=fen[x]; return s; }
int sum(int a, int b){ return (a<=b)*(sum(b)-sum(a-1)); }
void CDQ_Dnc(int l, int r){
if(l==r) return;
int mid = (l+r)>>1;
vector<Query2> v; v.clear();
for(int i = l; i <= r; i++){
if(i<=mid and !A[i].t) v.pb({A[i].y,A[i].z,A[i].i,A[i].t});
if(i>mid and A[i].t) v.pb({A[i].y,A[i].z,A[i].i,A[i].t});
}
sort(all(v), [&](Query2 a, Query2 b){
if(a.y==b.y) return a.t<b.t;
return a.y>b.y;
});
vector<int> xd; xd.clear();
for(auto [y,z,i,t] : v){
if(!t) upd(z,1),xd.pb(z);
else ans[i]+=sum(z,mxN-1);
}
for(auto u : xd) upd(u,-1);
CDQ_Dnc(l,mid), CDQ_Dnc(mid+1,r);
}
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> q; int x, y, z;
vector<int> v; v.clear();
for(int i = 0; i < n; i++){
cin >> x >> y; z = x+y;
v.pb(x), v.pb(y), v.pb(z);
A.pb({x,y,z,i,0});
}
for(int i = 0; i < q; i++){
cin >> x >> y >> z;
v.pb(x), v.pb(y), v.pb(z);
A.pb({x,y,z,i,1});
}
sort(all(v)); v.erase(unique(all(v)),end(v));
for(auto &[x,y,z,i,t] : A){
x = lower_bound(all(v),x)-begin(v)+1;
y = lower_bound(all(v),y)-begin(v)+1;
z = lower_bound(all(v),z)-begin(v)+1;
}
sort(all(A),[&](Query a, Query b){
if(a.x==b.x) return a.t<b.t;
return a.x>b.x;
});
CDQ_Dnc(0,n+q-1);
for(int i = 0; i < q; i++) cout << ans[i] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
9 ms |
724 KB |
Output is correct |
8 |
Correct |
10 ms |
812 KB |
Output is correct |
9 |
Correct |
9 ms |
812 KB |
Output is correct |
10 |
Correct |
9 ms |
724 KB |
Output is correct |
11 |
Correct |
10 ms |
920 KB |
Output is correct |
12 |
Correct |
7 ms |
728 KB |
Output is correct |
13 |
Correct |
11 ms |
856 KB |
Output is correct |
14 |
Correct |
10 ms |
852 KB |
Output is correct |
15 |
Correct |
11 ms |
884 KB |
Output is correct |
16 |
Correct |
8 ms |
852 KB |
Output is correct |
17 |
Correct |
10 ms |
852 KB |
Output is correct |
18 |
Correct |
6 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
383 ms |
12412 KB |
Output is correct |
2 |
Correct |
354 ms |
14932 KB |
Output is correct |
3 |
Correct |
357 ms |
15024 KB |
Output is correct |
4 |
Correct |
300 ms |
14012 KB |
Output is correct |
5 |
Correct |
309 ms |
14596 KB |
Output is correct |
6 |
Correct |
262 ms |
13388 KB |
Output is correct |
7 |
Correct |
362 ms |
16884 KB |
Output is correct |
8 |
Correct |
363 ms |
15028 KB |
Output is correct |
9 |
Correct |
331 ms |
16748 KB |
Output is correct |
10 |
Correct |
294 ms |
15596 KB |
Output is correct |
11 |
Correct |
262 ms |
13936 KB |
Output is correct |
12 |
Correct |
239 ms |
13244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
383 ms |
12412 KB |
Output is correct |
2 |
Correct |
354 ms |
14932 KB |
Output is correct |
3 |
Correct |
357 ms |
15024 KB |
Output is correct |
4 |
Correct |
300 ms |
14012 KB |
Output is correct |
5 |
Correct |
309 ms |
14596 KB |
Output is correct |
6 |
Correct |
262 ms |
13388 KB |
Output is correct |
7 |
Correct |
362 ms |
16884 KB |
Output is correct |
8 |
Correct |
363 ms |
15028 KB |
Output is correct |
9 |
Correct |
331 ms |
16748 KB |
Output is correct |
10 |
Correct |
294 ms |
15596 KB |
Output is correct |
11 |
Correct |
262 ms |
13936 KB |
Output is correct |
12 |
Correct |
239 ms |
13244 KB |
Output is correct |
13 |
Correct |
382 ms |
15444 KB |
Output is correct |
14 |
Correct |
380 ms |
15308 KB |
Output is correct |
15 |
Correct |
363 ms |
14928 KB |
Output is correct |
16 |
Correct |
324 ms |
14480 KB |
Output is correct |
17 |
Correct |
334 ms |
14888 KB |
Output is correct |
18 |
Correct |
276 ms |
13344 KB |
Output is correct |
19 |
Correct |
393 ms |
15444 KB |
Output is correct |
20 |
Correct |
437 ms |
15520 KB |
Output is correct |
21 |
Correct |
376 ms |
16704 KB |
Output is correct |
22 |
Correct |
281 ms |
15672 KB |
Output is correct |
23 |
Correct |
255 ms |
13884 KB |
Output is correct |
24 |
Correct |
245 ms |
12556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
9 ms |
724 KB |
Output is correct |
8 |
Correct |
10 ms |
812 KB |
Output is correct |
9 |
Correct |
9 ms |
812 KB |
Output is correct |
10 |
Correct |
9 ms |
724 KB |
Output is correct |
11 |
Correct |
10 ms |
920 KB |
Output is correct |
12 |
Correct |
7 ms |
728 KB |
Output is correct |
13 |
Correct |
11 ms |
856 KB |
Output is correct |
14 |
Correct |
10 ms |
852 KB |
Output is correct |
15 |
Correct |
11 ms |
884 KB |
Output is correct |
16 |
Correct |
8 ms |
852 KB |
Output is correct |
17 |
Correct |
10 ms |
852 KB |
Output is correct |
18 |
Correct |
6 ms |
724 KB |
Output is correct |
19 |
Correct |
383 ms |
12412 KB |
Output is correct |
20 |
Correct |
354 ms |
14932 KB |
Output is correct |
21 |
Correct |
357 ms |
15024 KB |
Output is correct |
22 |
Correct |
300 ms |
14012 KB |
Output is correct |
23 |
Correct |
309 ms |
14596 KB |
Output is correct |
24 |
Correct |
262 ms |
13388 KB |
Output is correct |
25 |
Correct |
362 ms |
16884 KB |
Output is correct |
26 |
Correct |
363 ms |
15028 KB |
Output is correct |
27 |
Correct |
331 ms |
16748 KB |
Output is correct |
28 |
Correct |
294 ms |
15596 KB |
Output is correct |
29 |
Correct |
262 ms |
13936 KB |
Output is correct |
30 |
Correct |
239 ms |
13244 KB |
Output is correct |
31 |
Correct |
382 ms |
15444 KB |
Output is correct |
32 |
Correct |
380 ms |
15308 KB |
Output is correct |
33 |
Correct |
363 ms |
14928 KB |
Output is correct |
34 |
Correct |
324 ms |
14480 KB |
Output is correct |
35 |
Correct |
334 ms |
14888 KB |
Output is correct |
36 |
Correct |
276 ms |
13344 KB |
Output is correct |
37 |
Correct |
393 ms |
15444 KB |
Output is correct |
38 |
Correct |
437 ms |
15520 KB |
Output is correct |
39 |
Correct |
376 ms |
16704 KB |
Output is correct |
40 |
Correct |
281 ms |
15672 KB |
Output is correct |
41 |
Correct |
255 ms |
13884 KB |
Output is correct |
42 |
Correct |
245 ms |
12556 KB |
Output is correct |
43 |
Correct |
416 ms |
19132 KB |
Output is correct |
44 |
Correct |
419 ms |
19156 KB |
Output is correct |
45 |
Correct |
455 ms |
19088 KB |
Output is correct |
46 |
Correct |
367 ms |
16804 KB |
Output is correct |
47 |
Correct |
340 ms |
17256 KB |
Output is correct |
48 |
Correct |
283 ms |
13240 KB |
Output is correct |
49 |
Correct |
420 ms |
20900 KB |
Output is correct |
50 |
Correct |
402 ms |
19188 KB |
Output is correct |
51 |
Correct |
427 ms |
20908 KB |
Output is correct |
52 |
Correct |
331 ms |
17684 KB |
Output is correct |
53 |
Correct |
267 ms |
15096 KB |
Output is correct |