#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#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; };
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)); }
vector<Query> A;
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){
return mp(a.y,-a.t)>mp(b.y,-b.t);
});
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 = lb(all(v),x)-begin(v)+1;
y = lb(all(v),y)-begin(v)+1;
z = lb(all(v),z)-begin(v)+1;
}
sort(all(A),[&](Query a, Query b){
return mp(a.x,-a.t)>mp(b.x,-b.t);
});
CDQ_Dnc(0,n+q-1);
for(int i = 0; i < q; i++) cout << ans[i] << "\n";
}
Compilation message
examination.cpp: In function 'void CDQ_Dnc(int, int)':
examination.cpp:18:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
18 | if(l==r) return; int mid = (l+r)>>1;
| ^~
examination.cpp:18:19: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
18 | if(l==r) return; int mid = (l+r)>>1;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
10 ms |
784 KB |
Output is correct |
8 |
Correct |
10 ms |
800 KB |
Output is correct |
9 |
Correct |
10 ms |
772 KB |
Output is correct |
10 |
Correct |
9 ms |
724 KB |
Output is correct |
11 |
Correct |
9 ms |
780 KB |
Output is correct |
12 |
Correct |
7 ms |
724 KB |
Output is correct |
13 |
Correct |
9 ms |
724 KB |
Output is correct |
14 |
Correct |
9 ms |
780 KB |
Output is correct |
15 |
Correct |
8 ms |
800 KB |
Output is correct |
16 |
Correct |
7 ms |
828 KB |
Output is correct |
17 |
Correct |
7 ms |
724 KB |
Output is correct |
18 |
Correct |
5 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
385 ms |
14920 KB |
Output is correct |
2 |
Correct |
398 ms |
12428 KB |
Output is correct |
3 |
Correct |
367 ms |
12404 KB |
Output is correct |
4 |
Correct |
292 ms |
12344 KB |
Output is correct |
5 |
Correct |
322 ms |
12732 KB |
Output is correct |
6 |
Correct |
274 ms |
12452 KB |
Output is correct |
7 |
Correct |
372 ms |
14484 KB |
Output is correct |
8 |
Correct |
330 ms |
12432 KB |
Output is correct |
9 |
Correct |
368 ms |
14516 KB |
Output is correct |
10 |
Correct |
298 ms |
13924 KB |
Output is correct |
11 |
Correct |
263 ms |
12076 KB |
Output is correct |
12 |
Correct |
206 ms |
12448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
385 ms |
14920 KB |
Output is correct |
2 |
Correct |
398 ms |
12428 KB |
Output is correct |
3 |
Correct |
367 ms |
12404 KB |
Output is correct |
4 |
Correct |
292 ms |
12344 KB |
Output is correct |
5 |
Correct |
322 ms |
12732 KB |
Output is correct |
6 |
Correct |
274 ms |
12452 KB |
Output is correct |
7 |
Correct |
372 ms |
14484 KB |
Output is correct |
8 |
Correct |
330 ms |
12432 KB |
Output is correct |
9 |
Correct |
368 ms |
14516 KB |
Output is correct |
10 |
Correct |
298 ms |
13924 KB |
Output is correct |
11 |
Correct |
263 ms |
12076 KB |
Output is correct |
12 |
Correct |
206 ms |
12448 KB |
Output is correct |
13 |
Correct |
394 ms |
12576 KB |
Output is correct |
14 |
Correct |
439 ms |
12520 KB |
Output is correct |
15 |
Correct |
353 ms |
12464 KB |
Output is correct |
16 |
Correct |
329 ms |
12256 KB |
Output is correct |
17 |
Correct |
389 ms |
12728 KB |
Output is correct |
18 |
Correct |
257 ms |
12436 KB |
Output is correct |
19 |
Correct |
389 ms |
12508 KB |
Output is correct |
20 |
Correct |
413 ms |
12556 KB |
Output is correct |
21 |
Correct |
382 ms |
13704 KB |
Output is correct |
22 |
Correct |
286 ms |
13952 KB |
Output is correct |
23 |
Correct |
270 ms |
12160 KB |
Output is correct |
24 |
Correct |
206 ms |
11444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
10 ms |
784 KB |
Output is correct |
8 |
Correct |
10 ms |
800 KB |
Output is correct |
9 |
Correct |
10 ms |
772 KB |
Output is correct |
10 |
Correct |
9 ms |
724 KB |
Output is correct |
11 |
Correct |
9 ms |
780 KB |
Output is correct |
12 |
Correct |
7 ms |
724 KB |
Output is correct |
13 |
Correct |
9 ms |
724 KB |
Output is correct |
14 |
Correct |
9 ms |
780 KB |
Output is correct |
15 |
Correct |
8 ms |
800 KB |
Output is correct |
16 |
Correct |
7 ms |
828 KB |
Output is correct |
17 |
Correct |
7 ms |
724 KB |
Output is correct |
18 |
Correct |
5 ms |
724 KB |
Output is correct |
19 |
Correct |
385 ms |
14920 KB |
Output is correct |
20 |
Correct |
398 ms |
12428 KB |
Output is correct |
21 |
Correct |
367 ms |
12404 KB |
Output is correct |
22 |
Correct |
292 ms |
12344 KB |
Output is correct |
23 |
Correct |
322 ms |
12732 KB |
Output is correct |
24 |
Correct |
274 ms |
12452 KB |
Output is correct |
25 |
Correct |
372 ms |
14484 KB |
Output is correct |
26 |
Correct |
330 ms |
12432 KB |
Output is correct |
27 |
Correct |
368 ms |
14516 KB |
Output is correct |
28 |
Correct |
298 ms |
13924 KB |
Output is correct |
29 |
Correct |
263 ms |
12076 KB |
Output is correct |
30 |
Correct |
206 ms |
12448 KB |
Output is correct |
31 |
Correct |
394 ms |
12576 KB |
Output is correct |
32 |
Correct |
439 ms |
12520 KB |
Output is correct |
33 |
Correct |
353 ms |
12464 KB |
Output is correct |
34 |
Correct |
329 ms |
12256 KB |
Output is correct |
35 |
Correct |
389 ms |
12728 KB |
Output is correct |
36 |
Correct |
257 ms |
12436 KB |
Output is correct |
37 |
Correct |
389 ms |
12508 KB |
Output is correct |
38 |
Correct |
413 ms |
12556 KB |
Output is correct |
39 |
Correct |
382 ms |
13704 KB |
Output is correct |
40 |
Correct |
286 ms |
13952 KB |
Output is correct |
41 |
Correct |
270 ms |
12160 KB |
Output is correct |
42 |
Correct |
206 ms |
11444 KB |
Output is correct |
43 |
Correct |
455 ms |
14188 KB |
Output is correct |
44 |
Correct |
429 ms |
14244 KB |
Output is correct |
45 |
Correct |
441 ms |
14204 KB |
Output is correct |
46 |
Correct |
361 ms |
13428 KB |
Output is correct |
47 |
Correct |
358 ms |
13848 KB |
Output is correct |
48 |
Correct |
286 ms |
12124 KB |
Output is correct |
49 |
Correct |
448 ms |
16244 KB |
Output is correct |
50 |
Correct |
410 ms |
14284 KB |
Output is correct |
51 |
Correct |
421 ms |
16108 KB |
Output is correct |
52 |
Correct |
337 ms |
14544 KB |
Output is correct |
53 |
Correct |
268 ms |
12716 KB |
Output is correct |