Submission #123693

# Submission time Handle Problem Language Result Execution time Memory
123693 2019-07-02T04:20:14 Z 임유진(#3031) Examination (JOI19_examination) C++14
100 / 100
744 ms 119288 KB
#include<stdio.h>
#include<algorithm>

using namespace std;

#define MAXN 100005
#define fi first
#define se second

typedef pair<int, int> pii;

struct NOD {
	NOD *lef, *rig;
	int cnt;

	NOD();
} *nil, *xpst[MAXN], *ypst[MAXN];

NOD::NOD(){
	lef = rig = nil;
	cnt = 0;
}

int X[MAXN], Y[MAXN], A[MAXN], B[MAXN], C[MAXN];
pii xs[MAXN], ds[MAXN], ys[MAXN];
int xidx[MAXN], didx[MAXN], yidx[MAXN];
int ans[MAXN];

void mkpst(NOD *bf, NOD *nw, int l, int r, int x) {
	nw -> cnt = bf -> cnt + 1;
	if(l == r) return;
	int m = (l + r) / 2;
	if(x <= m) {
		nw -> lef = new NOD();
		nw -> rig = bf -> rig;
		mkpst(bf -> lef, nw -> lef, l, m, x);
	}
	else {
		nw -> lef = bf -> lef;
		nw -> rig = new NOD();
		mkpst(bf -> rig, nw -> rig, m + 1, r, x);
	}
}

int gpst(NOD *p, int l, int r, int x, int y) {
	if(x <= l && r <=  y) return p -> cnt;
	if(r < x || y < l) return 0;
	int m = (l + r) / 2;
	return gpst(p -> lef, l, m, x, y) + gpst(p -> rig, m + 1, r, x, y);
}

int main() {
	int N, Q;

	scanf("%d%d", &N, &Q);
	for(int i = 1; i <= N; i++) scanf("%d%d", X+i, Y+i);
	for(int i = 0; i < Q; i++) scanf("%d%d%d", A+i, B+i, C+i);

	for(int i = 1; i <= N; i++) {
		xs[i] = make_pair(X[i], i);
		ys[i] = make_pair(Y[i], i);
		ds[i] = make_pair(X[i] + Y[i], i);
	}
	sort(xs + 1, xs + N + 1);
	sort(ys + 1, ys + N + 1);
	sort(ds + 1, ds + N + 1);

	for(int i = 1; i <= N; i++) {
		xidx[xs[i].se] = i;
		didx[ds[i].se] = i;
		yidx[ys[i].se] = i;
	}
	
	nil = new NOD();
	nil -> lef = nil -> rig = nil;
	xpst[0] = nil;
	for(int i = 1; i <= N; i++) {
		xpst[i] = new NOD();
		mkpst(xpst[i-1], xpst[i], 1, N, xidx[ds[i].se]);
	}
	ypst[N + 1] = nil;
	for(int i = N; i > 0; i--) {
		ypst[i] = new NOD();
		mkpst(ypst[i + 1], ypst[i], 1, N, yidx[ds[i].se]);
	}

	for(int i = 0; i < Q; i++) {
		C[i] = max(C[i], A[i] + B[i]);
		int x = lower_bound(xs + 1, xs + N + 1, make_pair(A[i], 0)) - xs;
		int y = lower_bound(ys + 1, ys + N + 1, make_pair(B[i], 0)) - ys;
		int d = lower_bound(ds + 1, ds + N + 1, make_pair(C[i], 0)) - ds;
		int lcnt = x - 1;
		int dcnt = gpst(xpst[d - 1], 1, N, x, N);
		int rcnt = gpst(ypst[d], 1, N, 1, y - 1);
		ans[i] = N - lcnt - dcnt - rcnt;
	}

	for(int i = 0; i < Q; i++) printf("%d\n", ans[i]);
	return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &Q);
  ~~~~~^~~~~~~~~~~~~~~~
examination.cpp:56:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= N; i++) scanf("%d%d", X+i, Y+i);
                              ~~~~~^~~~~~~~~~~~~~~~~~
examination.cpp:57:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i < Q; i++) scanf("%d%d%d", A+i, B+i, C+i);
                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 248 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 12 ms 2936 KB Output is correct
8 Correct 13 ms 2936 KB Output is correct
9 Correct 12 ms 3040 KB Output is correct
10 Correct 11 ms 2936 KB Output is correct
11 Correct 11 ms 2936 KB Output is correct
12 Correct 9 ms 2936 KB Output is correct
13 Correct 12 ms 2936 KB Output is correct
14 Correct 12 ms 2936 KB Output is correct
15 Correct 12 ms 2936 KB Output is correct
16 Correct 10 ms 2936 KB Output is correct
17 Correct 10 ms 2936 KB Output is correct
18 Correct 8 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 690 ms 119060 KB Output is correct
2 Correct 694 ms 119144 KB Output is correct
3 Correct 720 ms 119132 KB Output is correct
4 Correct 574 ms 119148 KB Output is correct
5 Correct 527 ms 119196 KB Output is correct
6 Correct 343 ms 119132 KB Output is correct
7 Correct 735 ms 119240 KB Output is correct
8 Correct 561 ms 119160 KB Output is correct
9 Correct 428 ms 119120 KB Output is correct
10 Correct 408 ms 119032 KB Output is correct
11 Correct 423 ms 118956 KB Output is correct
12 Correct 263 ms 118708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 690 ms 119060 KB Output is correct
2 Correct 694 ms 119144 KB Output is correct
3 Correct 720 ms 119132 KB Output is correct
4 Correct 574 ms 119148 KB Output is correct
5 Correct 527 ms 119196 KB Output is correct
6 Correct 343 ms 119132 KB Output is correct
7 Correct 735 ms 119240 KB Output is correct
8 Correct 561 ms 119160 KB Output is correct
9 Correct 428 ms 119120 KB Output is correct
10 Correct 408 ms 119032 KB Output is correct
11 Correct 423 ms 118956 KB Output is correct
12 Correct 263 ms 118708 KB Output is correct
13 Correct 699 ms 119104 KB Output is correct
14 Correct 744 ms 119120 KB Output is correct
15 Correct 697 ms 119036 KB Output is correct
16 Correct 563 ms 119156 KB Output is correct
17 Correct 508 ms 119160 KB Output is correct
18 Correct 352 ms 119160 KB Output is correct
19 Correct 653 ms 119032 KB Output is correct
20 Correct 698 ms 119004 KB Output is correct
21 Correct 621 ms 119140 KB Output is correct
22 Correct 402 ms 119104 KB Output is correct
23 Correct 407 ms 119160 KB Output is correct
24 Correct 258 ms 118904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 248 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 12 ms 2936 KB Output is correct
8 Correct 13 ms 2936 KB Output is correct
9 Correct 12 ms 3040 KB Output is correct
10 Correct 11 ms 2936 KB Output is correct
11 Correct 11 ms 2936 KB Output is correct
12 Correct 9 ms 2936 KB Output is correct
13 Correct 12 ms 2936 KB Output is correct
14 Correct 12 ms 2936 KB Output is correct
15 Correct 12 ms 2936 KB Output is correct
16 Correct 10 ms 2936 KB Output is correct
17 Correct 10 ms 2936 KB Output is correct
18 Correct 8 ms 2936 KB Output is correct
19 Correct 690 ms 119060 KB Output is correct
20 Correct 694 ms 119144 KB Output is correct
21 Correct 720 ms 119132 KB Output is correct
22 Correct 574 ms 119148 KB Output is correct
23 Correct 527 ms 119196 KB Output is correct
24 Correct 343 ms 119132 KB Output is correct
25 Correct 735 ms 119240 KB Output is correct
26 Correct 561 ms 119160 KB Output is correct
27 Correct 428 ms 119120 KB Output is correct
28 Correct 408 ms 119032 KB Output is correct
29 Correct 423 ms 118956 KB Output is correct
30 Correct 263 ms 118708 KB Output is correct
31 Correct 699 ms 119104 KB Output is correct
32 Correct 744 ms 119120 KB Output is correct
33 Correct 697 ms 119036 KB Output is correct
34 Correct 563 ms 119156 KB Output is correct
35 Correct 508 ms 119160 KB Output is correct
36 Correct 352 ms 119160 KB Output is correct
37 Correct 653 ms 119032 KB Output is correct
38 Correct 698 ms 119004 KB Output is correct
39 Correct 621 ms 119140 KB Output is correct
40 Correct 402 ms 119104 KB Output is correct
41 Correct 407 ms 119160 KB Output is correct
42 Correct 258 ms 118904 KB Output is correct
43 Correct 658 ms 119112 KB Output is correct
44 Correct 710 ms 119288 KB Output is correct
45 Correct 728 ms 119136 KB Output is correct
46 Correct 522 ms 119160 KB Output is correct
47 Correct 525 ms 119108 KB Output is correct
48 Correct 347 ms 118960 KB Output is correct
49 Correct 621 ms 119288 KB Output is correct
50 Correct 613 ms 119288 KB Output is correct
51 Correct 599 ms 119176 KB Output is correct
52 Correct 407 ms 119032 KB Output is correct
53 Correct 433 ms 119016 KB Output is correct