Submission #755051

# Submission time Handle Problem Language Result Execution time Memory
755051 2023-06-09T10:54:39 Z Dan4Life Examination (JOI19_examination) C++17
100 / 100
481 ms 25204 KB
#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 Query{ int x, y, z, i, t; } A[mxN];
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<Query> v; v.clear();
	for(int i = l; i <= r; i++){
		if(i<=mid and !A[i].t) v.pb({0,A[i].y,A[i].z,A[i].i,A[i].t});
		if(i>mid and A[i].t) v.pb({0,A[i].y,A[i].z,A[i].i,A[i].t});
	}
	sort(all(v), [&](Query a, Query b){
		return mp(a.y,-a.t)>mp(b.y,-b.t);
	});
	vector<int> xd; xd.clear();
	for(auto [x,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;
		A[i]={x,y,z,i-n,i>=n};
		v.pb(x), v.pb(y), v.pb(z);
	}
	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(A,A+n+q,[&](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:16:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   16 |  if(l==r) return; int mid = (l+r)>>1;
      |  ^~
examination.cpp:16:19: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   16 |  if(l==r) return; int mid = (l+r)>>1;
      |                   ^~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 12076 KB Output is correct
2 Correct 18 ms 12116 KB Output is correct
3 Correct 18 ms 12072 KB Output is correct
4 Correct 18 ms 12000 KB Output is correct
5 Correct 19 ms 12036 KB Output is correct
6 Correct 18 ms 12016 KB Output is correct
7 Correct 39 ms 12332 KB Output is correct
8 Correct 37 ms 12372 KB Output is correct
9 Correct 40 ms 12420 KB Output is correct
10 Correct 37 ms 12392 KB Output is correct
11 Correct 36 ms 12416 KB Output is correct
12 Correct 25 ms 12408 KB Output is correct
13 Correct 38 ms 12408 KB Output is correct
14 Correct 37 ms 12424 KB Output is correct
15 Correct 38 ms 12372 KB Output is correct
16 Correct 32 ms 12464 KB Output is correct
17 Correct 35 ms 12384 KB Output is correct
18 Correct 18 ms 12376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 374 ms 20460 KB Output is correct
2 Correct 442 ms 20540 KB Output is correct
3 Correct 400 ms 20416 KB Output is correct
4 Correct 309 ms 20408 KB Output is correct
5 Correct 326 ms 21148 KB Output is correct
6 Correct 266 ms 20760 KB Output is correct
7 Correct 387 ms 23572 KB Output is correct
8 Correct 358 ms 20424 KB Output is correct
9 Correct 368 ms 23356 KB Output is correct
10 Correct 295 ms 21948 KB Output is correct
11 Correct 265 ms 20384 KB Output is correct
12 Correct 224 ms 20436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 374 ms 20460 KB Output is correct
2 Correct 442 ms 20540 KB Output is correct
3 Correct 400 ms 20416 KB Output is correct
4 Correct 309 ms 20408 KB Output is correct
5 Correct 326 ms 21148 KB Output is correct
6 Correct 266 ms 20760 KB Output is correct
7 Correct 387 ms 23572 KB Output is correct
8 Correct 358 ms 20424 KB Output is correct
9 Correct 368 ms 23356 KB Output is correct
10 Correct 295 ms 21948 KB Output is correct
11 Correct 265 ms 20384 KB Output is correct
12 Correct 224 ms 20436 KB Output is correct
13 Correct 413 ms 20568 KB Output is correct
14 Correct 405 ms 20536 KB Output is correct
15 Correct 380 ms 20468 KB Output is correct
16 Correct 354 ms 20260 KB Output is correct
17 Correct 353 ms 21180 KB Output is correct
18 Correct 268 ms 20732 KB Output is correct
19 Correct 423 ms 20560 KB Output is correct
20 Correct 421 ms 20536 KB Output is correct
21 Correct 396 ms 22964 KB Output is correct
22 Correct 305 ms 22000 KB Output is correct
23 Correct 272 ms 20156 KB Output is correct
24 Correct 213 ms 20396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 12076 KB Output is correct
2 Correct 18 ms 12116 KB Output is correct
3 Correct 18 ms 12072 KB Output is correct
4 Correct 18 ms 12000 KB Output is correct
5 Correct 19 ms 12036 KB Output is correct
6 Correct 18 ms 12016 KB Output is correct
7 Correct 39 ms 12332 KB Output is correct
8 Correct 37 ms 12372 KB Output is correct
9 Correct 40 ms 12420 KB Output is correct
10 Correct 37 ms 12392 KB Output is correct
11 Correct 36 ms 12416 KB Output is correct
12 Correct 25 ms 12408 KB Output is correct
13 Correct 38 ms 12408 KB Output is correct
14 Correct 37 ms 12424 KB Output is correct
15 Correct 38 ms 12372 KB Output is correct
16 Correct 32 ms 12464 KB Output is correct
17 Correct 35 ms 12384 KB Output is correct
18 Correct 18 ms 12376 KB Output is correct
19 Correct 374 ms 20460 KB Output is correct
20 Correct 442 ms 20540 KB Output is correct
21 Correct 400 ms 20416 KB Output is correct
22 Correct 309 ms 20408 KB Output is correct
23 Correct 326 ms 21148 KB Output is correct
24 Correct 266 ms 20760 KB Output is correct
25 Correct 387 ms 23572 KB Output is correct
26 Correct 358 ms 20424 KB Output is correct
27 Correct 368 ms 23356 KB Output is correct
28 Correct 295 ms 21948 KB Output is correct
29 Correct 265 ms 20384 KB Output is correct
30 Correct 224 ms 20436 KB Output is correct
31 Correct 413 ms 20568 KB Output is correct
32 Correct 405 ms 20536 KB Output is correct
33 Correct 380 ms 20468 KB Output is correct
34 Correct 354 ms 20260 KB Output is correct
35 Correct 353 ms 21180 KB Output is correct
36 Correct 268 ms 20732 KB Output is correct
37 Correct 423 ms 20560 KB Output is correct
38 Correct 421 ms 20536 KB Output is correct
39 Correct 396 ms 22964 KB Output is correct
40 Correct 305 ms 22000 KB Output is correct
41 Correct 272 ms 20156 KB Output is correct
42 Correct 213 ms 20396 KB Output is correct
43 Correct 449 ms 22180 KB Output is correct
44 Correct 453 ms 22272 KB Output is correct
45 Correct 440 ms 22212 KB Output is correct
46 Correct 361 ms 21440 KB Output is correct
47 Correct 360 ms 22328 KB Output is correct
48 Correct 278 ms 20832 KB Output is correct
49 Correct 481 ms 25204 KB Output is correct
50 Correct 443 ms 22080 KB Output is correct
51 Correct 417 ms 25128 KB Output is correct
52 Correct 369 ms 22952 KB Output is correct
53 Correct 316 ms 20652 KB Output is correct