답안 #787983

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
787983 2023-07-19T15:47:01 Z rainboy Gym Badges (NOI22_gymbadges) C
100 / 100
416 ms 33828 KB
#include <stdio.h>
#include <string.h>

#define N	500000
#define N_	(1 << 19)	/* N_ = pow2(ceil(log2(N))) */
#define INF	0x3f3f3f3f3f3f3f3fLL

long long min(long long a, long long b) { return a < b ? a : b; }

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

int *vv;

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (vv[ii[j]] == vv[i_])
				j++;
			else if (vv[ii[j]] < vv[i_]) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		sort(ii, l, i);
		l = k;
	}
}

long long ss[N_ * 2], dd[N_ * 2]; int n_;

void pul(int i) {
	int l = i << 1, r = l | 1;

	ss[i] = ss[l] + ss[r];
	dd[i] = min(dd[l], dd[r] == INF ? INF : dd[r] - ss[l]);
}

void build(int n) {
	int i;

	n_ = 1;
	while (n_ < n)
		n_ <<= 1;
	memset(dd + n_, 0x3f, n_ * sizeof *dd);
	for (i = n_ - 1; i > 0; i--)
		pul(i);
}

void update(int i, int x, long long y) {
	i += n_;
	ss[i] = x, dd[i] = y == INF ? INF : y - x;
	while (i > 1)
		pul(i >>= 1);
}

int main() {
	static int xx[N], yy[N], ii[N], idx[N];
	int n, h, i, k;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &xx[i]);
	for (i = 0; i < n; i++)
		scanf("%d", &yy[i]), yy[i] += xx[i];
	for (i = 0; i < n; i++)
		ii[i] = i;
	vv = yy, sort(ii, 0, n);
	for (i = 0; i < n; i++)
		idx[ii[i]] = i;
	vv = xx, sort(ii, 0, n);
	build(n);
	k = 0;
	for (h = 0; h < n; h++) {
		i = ii[h];
		update(idx[i], xx[i], yy[i]);
		if (dd[1] >= 0)
			k++;
		else
			update(idx[i], 0, INF);
	}
	printf("%d\n", k);
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:68:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
Main.c:70:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |   scanf("%d", &xx[i]);
      |   ^~~~~~~~~~~~~~~~~~~
Main.c:72:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |   scanf("%d", &yy[i]), yy[i] += xx[i];
      |   ^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 288 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 288 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 304 ms 24704 KB Output is correct
2 Correct 309 ms 24660 KB Output is correct
3 Correct 301 ms 24684 KB Output is correct
4 Correct 305 ms 24632 KB Output is correct
5 Correct 308 ms 24664 KB Output is correct
6 Correct 297 ms 24712 KB Output is correct
7 Correct 299 ms 24712 KB Output is correct
8 Correct 293 ms 24728 KB Output is correct
9 Correct 303 ms 24676 KB Output is correct
10 Correct 296 ms 24620 KB Output is correct
11 Correct 224 ms 24664 KB Output is correct
12 Correct 222 ms 24660 KB Output is correct
13 Correct 226 ms 24592 KB Output is correct
14 Correct 221 ms 24640 KB Output is correct
15 Correct 220 ms 24680 KB Output is correct
16 Correct 265 ms 31988 KB Output is correct
17 Correct 264 ms 32024 KB Output is correct
18 Correct 266 ms 32052 KB Output is correct
19 Correct 258 ms 31992 KB Output is correct
20 Correct 270 ms 32148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 288 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 288 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 3 ms 724 KB Output is correct
23 Correct 3 ms 724 KB Output is correct
24 Correct 3 ms 724 KB Output is correct
25 Correct 3 ms 656 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 3 ms 724 KB Output is correct
29 Correct 3 ms 724 KB Output is correct
30 Correct 3 ms 688 KB Output is correct
31 Correct 3 ms 728 KB Output is correct
32 Correct 3 ms 716 KB Output is correct
33 Correct 3 ms 596 KB Output is correct
34 Correct 3 ms 724 KB Output is correct
35 Correct 3 ms 724 KB Output is correct
36 Correct 3 ms 596 KB Output is correct
37 Correct 3 ms 596 KB Output is correct
38 Correct 3 ms 596 KB Output is correct
39 Correct 3 ms 596 KB Output is correct
40 Correct 3 ms 680 KB Output is correct
41 Correct 3 ms 596 KB Output is correct
42 Correct 3 ms 716 KB Output is correct
43 Correct 3 ms 596 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 3 ms 596 KB Output is correct
46 Correct 3 ms 596 KB Output is correct
47 Correct 3 ms 692 KB Output is correct
48 Correct 3 ms 596 KB Output is correct
49 Correct 3 ms 596 KB Output is correct
50 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 288 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 288 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 304 ms 24704 KB Output is correct
22 Correct 309 ms 24660 KB Output is correct
23 Correct 301 ms 24684 KB Output is correct
24 Correct 305 ms 24632 KB Output is correct
25 Correct 308 ms 24664 KB Output is correct
26 Correct 297 ms 24712 KB Output is correct
27 Correct 299 ms 24712 KB Output is correct
28 Correct 293 ms 24728 KB Output is correct
29 Correct 303 ms 24676 KB Output is correct
30 Correct 296 ms 24620 KB Output is correct
31 Correct 224 ms 24664 KB Output is correct
32 Correct 222 ms 24660 KB Output is correct
33 Correct 226 ms 24592 KB Output is correct
34 Correct 221 ms 24640 KB Output is correct
35 Correct 220 ms 24680 KB Output is correct
36 Correct 265 ms 31988 KB Output is correct
37 Correct 264 ms 32024 KB Output is correct
38 Correct 266 ms 32052 KB Output is correct
39 Correct 258 ms 31992 KB Output is correct
40 Correct 270 ms 32148 KB Output is correct
41 Correct 3 ms 724 KB Output is correct
42 Correct 3 ms 724 KB Output is correct
43 Correct 3 ms 724 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 3 ms 656 KB Output is correct
46 Correct 3 ms 596 KB Output is correct
47 Correct 3 ms 724 KB Output is correct
48 Correct 3 ms 724 KB Output is correct
49 Correct 3 ms 724 KB Output is correct
50 Correct 3 ms 688 KB Output is correct
51 Correct 3 ms 728 KB Output is correct
52 Correct 3 ms 716 KB Output is correct
53 Correct 3 ms 596 KB Output is correct
54 Correct 3 ms 724 KB Output is correct
55 Correct 3 ms 724 KB Output is correct
56 Correct 3 ms 596 KB Output is correct
57 Correct 3 ms 596 KB Output is correct
58 Correct 3 ms 596 KB Output is correct
59 Correct 3 ms 596 KB Output is correct
60 Correct 3 ms 680 KB Output is correct
61 Correct 3 ms 596 KB Output is correct
62 Correct 3 ms 716 KB Output is correct
63 Correct 3 ms 596 KB Output is correct
64 Correct 3 ms 724 KB Output is correct
65 Correct 3 ms 596 KB Output is correct
66 Correct 3 ms 596 KB Output is correct
67 Correct 3 ms 692 KB Output is correct
68 Correct 3 ms 596 KB Output is correct
69 Correct 3 ms 596 KB Output is correct
70 Correct 3 ms 596 KB Output is correct
71 Correct 0 ms 284 KB Output is correct
72 Correct 0 ms 340 KB Output is correct
73 Correct 377 ms 33728 KB Output is correct
74 Correct 401 ms 33624 KB Output is correct
75 Correct 390 ms 33720 KB Output is correct
76 Correct 378 ms 33692 KB Output is correct
77 Correct 416 ms 33712 KB Output is correct
78 Correct 364 ms 33428 KB Output is correct
79 Correct 405 ms 33408 KB Output is correct
80 Correct 383 ms 33472 KB Output is correct
81 Correct 371 ms 33428 KB Output is correct
82 Correct 368 ms 33408 KB Output is correct
83 Correct 362 ms 32764 KB Output is correct
84 Correct 357 ms 32860 KB Output is correct
85 Correct 381 ms 32872 KB Output is correct
86 Correct 353 ms 32792 KB Output is correct
87 Correct 350 ms 32744 KB Output is correct
88 Correct 344 ms 32252 KB Output is correct
89 Correct 345 ms 32188 KB Output is correct
90 Correct 353 ms 32160 KB Output is correct
91 Correct 345 ms 32236 KB Output is correct
92 Correct 354 ms 32256 KB Output is correct
93 Correct 323 ms 31884 KB Output is correct
94 Correct 329 ms 31876 KB Output is correct
95 Correct 336 ms 31868 KB Output is correct
96 Correct 353 ms 32012 KB Output is correct
97 Correct 332 ms 31892 KB Output is correct
98 Correct 373 ms 33556 KB Output is correct
99 Correct 397 ms 33656 KB Output is correct
100 Correct 369 ms 33828 KB Output is correct
101 Correct 326 ms 31292 KB Output is correct
102 Correct 319 ms 31304 KB Output is correct