#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+q; i++){
cin >> x >> y; z = x+y;
if(i>=n) cin >> z;
v.pb(x), v.pb(y), v.pb(z);
A.pb({x,y,z,i-n,i>=n});
}
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;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
340 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 |
724 KB |
Output is correct |
8 |
Correct |
10 ms |
784 KB |
Output is correct |
9 |
Correct |
10 ms |
768 KB |
Output is correct |
10 |
Correct |
8 ms |
724 KB |
Output is correct |
11 |
Correct |
8 ms |
724 KB |
Output is correct |
12 |
Correct |
6 ms |
776 KB |
Output is correct |
13 |
Correct |
10 ms |
724 KB |
Output is correct |
14 |
Correct |
9 ms |
788 KB |
Output is correct |
15 |
Correct |
11 ms |
724 KB |
Output is correct |
16 |
Correct |
7 ms |
724 KB |
Output is correct |
17 |
Correct |
8 ms |
724 KB |
Output is correct |
18 |
Correct |
6 ms |
784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
373 ms |
12448 KB |
Output is correct |
2 |
Correct |
372 ms |
12552 KB |
Output is correct |
3 |
Correct |
368 ms |
12540 KB |
Output is correct |
4 |
Correct |
300 ms |
12344 KB |
Output is correct |
5 |
Correct |
315 ms |
12844 KB |
Output is correct |
6 |
Correct |
246 ms |
12488 KB |
Output is correct |
7 |
Correct |
350 ms |
14488 KB |
Output is correct |
8 |
Correct |
340 ms |
12504 KB |
Output is correct |
9 |
Correct |
333 ms |
14372 KB |
Output is correct |
10 |
Correct |
271 ms |
13952 KB |
Output is correct |
11 |
Correct |
256 ms |
12224 KB |
Output is correct |
12 |
Correct |
221 ms |
12280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
373 ms |
12448 KB |
Output is correct |
2 |
Correct |
372 ms |
12552 KB |
Output is correct |
3 |
Correct |
368 ms |
12540 KB |
Output is correct |
4 |
Correct |
300 ms |
12344 KB |
Output is correct |
5 |
Correct |
315 ms |
12844 KB |
Output is correct |
6 |
Correct |
246 ms |
12488 KB |
Output is correct |
7 |
Correct |
350 ms |
14488 KB |
Output is correct |
8 |
Correct |
340 ms |
12504 KB |
Output is correct |
9 |
Correct |
333 ms |
14372 KB |
Output is correct |
10 |
Correct |
271 ms |
13952 KB |
Output is correct |
11 |
Correct |
256 ms |
12224 KB |
Output is correct |
12 |
Correct |
221 ms |
12280 KB |
Output is correct |
13 |
Correct |
404 ms |
12584 KB |
Output is correct |
14 |
Correct |
407 ms |
12520 KB |
Output is correct |
15 |
Correct |
387 ms |
12472 KB |
Output is correct |
16 |
Correct |
330 ms |
12264 KB |
Output is correct |
17 |
Correct |
319 ms |
12816 KB |
Output is correct |
18 |
Correct |
274 ms |
12440 KB |
Output is correct |
19 |
Correct |
385 ms |
12576 KB |
Output is correct |
20 |
Correct |
424 ms |
12484 KB |
Output is correct |
21 |
Correct |
391 ms |
13832 KB |
Output is correct |
22 |
Correct |
279 ms |
13860 KB |
Output is correct |
23 |
Correct |
291 ms |
12224 KB |
Output is correct |
24 |
Correct |
217 ms |
11560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
340 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 |
724 KB |
Output is correct |
8 |
Correct |
10 ms |
784 KB |
Output is correct |
9 |
Correct |
10 ms |
768 KB |
Output is correct |
10 |
Correct |
8 ms |
724 KB |
Output is correct |
11 |
Correct |
8 ms |
724 KB |
Output is correct |
12 |
Correct |
6 ms |
776 KB |
Output is correct |
13 |
Correct |
10 ms |
724 KB |
Output is correct |
14 |
Correct |
9 ms |
788 KB |
Output is correct |
15 |
Correct |
11 ms |
724 KB |
Output is correct |
16 |
Correct |
7 ms |
724 KB |
Output is correct |
17 |
Correct |
8 ms |
724 KB |
Output is correct |
18 |
Correct |
6 ms |
784 KB |
Output is correct |
19 |
Correct |
373 ms |
12448 KB |
Output is correct |
20 |
Correct |
372 ms |
12552 KB |
Output is correct |
21 |
Correct |
368 ms |
12540 KB |
Output is correct |
22 |
Correct |
300 ms |
12344 KB |
Output is correct |
23 |
Correct |
315 ms |
12844 KB |
Output is correct |
24 |
Correct |
246 ms |
12488 KB |
Output is correct |
25 |
Correct |
350 ms |
14488 KB |
Output is correct |
26 |
Correct |
340 ms |
12504 KB |
Output is correct |
27 |
Correct |
333 ms |
14372 KB |
Output is correct |
28 |
Correct |
271 ms |
13952 KB |
Output is correct |
29 |
Correct |
256 ms |
12224 KB |
Output is correct |
30 |
Correct |
221 ms |
12280 KB |
Output is correct |
31 |
Correct |
404 ms |
12584 KB |
Output is correct |
32 |
Correct |
407 ms |
12520 KB |
Output is correct |
33 |
Correct |
387 ms |
12472 KB |
Output is correct |
34 |
Correct |
330 ms |
12264 KB |
Output is correct |
35 |
Correct |
319 ms |
12816 KB |
Output is correct |
36 |
Correct |
274 ms |
12440 KB |
Output is correct |
37 |
Correct |
385 ms |
12576 KB |
Output is correct |
38 |
Correct |
424 ms |
12484 KB |
Output is correct |
39 |
Correct |
391 ms |
13832 KB |
Output is correct |
40 |
Correct |
279 ms |
13860 KB |
Output is correct |
41 |
Correct |
291 ms |
12224 KB |
Output is correct |
42 |
Correct |
217 ms |
11560 KB |
Output is correct |
43 |
Correct |
420 ms |
14360 KB |
Output is correct |
44 |
Correct |
424 ms |
14156 KB |
Output is correct |
45 |
Correct |
449 ms |
14184 KB |
Output is correct |
46 |
Correct |
348 ms |
13460 KB |
Output is correct |
47 |
Correct |
355 ms |
13868 KB |
Output is correct |
48 |
Correct |
273 ms |
12148 KB |
Output is correct |
49 |
Correct |
401 ms |
16244 KB |
Output is correct |
50 |
Correct |
429 ms |
14284 KB |
Output is correct |
51 |
Correct |
440 ms |
16160 KB |
Output is correct |
52 |
Correct |
338 ms |
14292 KB |
Output is correct |
53 |
Correct |
261 ms |
12596 KB |
Output is correct |