답안 #781036

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781036 2023-07-12T16:15:23 Z rainboy Vinjete (COI22_vinjete) C
69 / 100
148 ms 26732 KB
#include <stdio.h>
#include <stdlib.h>

#define N	100000
#define M	((N - 1) * 2)
#define N_	(1 << 18)	/* N_ = pow2(ceil(log2(M))) */

unsigned int X = 12345;

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

int ii[N - 1], jj[N - 1], xx[M], xx_[M], m;
int *eh[N], eo[N], ans[N];

void append(int i, int h) {
	int o = eo[i]++;

	if (o >= 2 && (o & o - 1) == 0)
		eh[i] = (int *) realloc(eh[i], o * 2 * sizeof *eh[i]);
	eh[i][o] = h;
}

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

		while (j < k)
			if (xx[hh[j]] == xx[h])
				j++;
			else if (xx[hh[j]] < xx[h]) {
				tmp = hh[i], hh[i] = hh[j], hh[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = hh[j], hh[j] = hh[k], hh[k] = tmp;
			}
		sort(hh, l, i);
		l = k;
	}
}

int st[N_ * 2], sum[N_ * 2], lz[N_ * 2], n_;

void pul(int i) {
	st[i] = lz[i] ? sum[i] : st[i << 1 | 0] + st[i << 1 | 1];
}

void put(int i, int x) {
	lz[i] += x, pul(i);
}

void pull(int i) {
	while (i > 1)
		pul(i >>= 1);
}

void build() {
	int h, i;

	n_ = 1;
	while (n_ < m - 1)
		n_ <<= 1;
	for (h = 0; h + 1 < m; h++)
		sum[n_ + h] = xx_[h + 1] - xx_[h];
	for (i = n_ - 1; i > 0; i--)
		sum[i] = sum[i << 1 | 0] + sum[i << 1 | 1], pul(i);
}

void update(int l, int r, int x) {
	int l_ = l += n_, r_ = r += n_;

	for ( ; l <= r; l >>= 1, r >>= 1) {
		if ((l & 1) == 1)
			put(l++, x);
		if ((r & 1) == 0)
			put(r--, x);
	}
	pull(l_), pull(r_);
}

void dfs(int p, int i) {
	int o;

	ans[i] = st[1];
	for (o = eo[i]; o--; ) {
		int h = eh[i][o], j = i ^ ii[h] ^ jj[h];

		if (j != p) {
			update(xx[h << 1 | 0], xx[h << 1 | 1] - 1, 1);
			dfs(i, j);
			update(xx[h << 1 | 0], xx[h << 1 | 1] - 1, -1);
		}
	}
}

int main() {
	static int hh[(N - 1) * 2];
	int n, h, h_, i, j, x;

	scanf("%d%*d", &n);
	for (i = 0; i < n; i++)
		eh[i] = (int *) malloc(2 * sizeof *eh[i]);
	for (h = 0; h < n - 1; h++) {
		scanf("%d%d%d%d", &i, &j, &xx[h << 1 | 0], &xx[h << 1 | 1]), i--, j--, xx[h << 1 | 1]++;
		ii[h] = i, jj[h] = j;
		append(i, h), append(j, h);
	}
	for (h = 0; h < (n - 1) * 2; h++)
		hh[h] = h;
	sort(hh, 0, (n - 1) * 2);
	m = 0;
	for (h = 0; h < (n - 1) * 2; ) {
		xx_[m] = x = xx[hh[h]];
		while (h < (n - 1) * 2 && xx[h_ = hh[h]] == x)
			xx[h_] = m, h++;
		m++;
	}
	build();
	dfs(-1, 0);
	for (i = 1; i < n; i++)
		printf("%d\n", ans[i]);
	return 0;
}

Compilation message

Main.c: In function 'append':
Main.c:20:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   20 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
Main.c: In function 'main':
Main.c:102:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |  scanf("%d%*d", &n);
      |  ^~~~~~~~~~~~~~~~~~
Main.c:106:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |   scanf("%d%d%d%d", &i, &j, &xx[h << 1 | 0], &xx[h << 1 | 1]), i--, j--, xx[h << 1 | 1]++;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 27 ms 7056 KB Output is correct
26 Correct 28 ms 7068 KB Output is correct
27 Correct 41 ms 8000 KB Output is correct
28 Correct 52 ms 7940 KB Output is correct
29 Correct 37 ms 8160 KB Output is correct
30 Correct 30 ms 8052 KB Output is correct
31 Correct 5 ms 1364 KB Output is correct
32 Correct 5 ms 1364 KB Output is correct
33 Correct 3 ms 1364 KB Output is correct
34 Correct 5 ms 1416 KB Output is correct
35 Correct 28 ms 3660 KB Output is correct
36 Correct 36 ms 3924 KB Output is correct
37 Correct 46 ms 4640 KB Output is correct
38 Correct 51 ms 4868 KB Output is correct
39 Correct 33 ms 4792 KB Output is correct
40 Correct 31 ms 4660 KB Output is correct
41 Correct 4 ms 980 KB Output is correct
42 Correct 3 ms 1052 KB Output is correct
43 Correct 30 ms 3404 KB Output is correct
44 Correct 31 ms 3396 KB Output is correct
45 Correct 43 ms 4280 KB Output is correct
46 Correct 49 ms 4296 KB Output is correct
47 Correct 30 ms 4368 KB Output is correct
48 Correct 40 ms 4304 KB Output is correct
49 Correct 3 ms 980 KB Output is correct
50 Correct 3 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 27 ms 7056 KB Output is correct
26 Correct 28 ms 7068 KB Output is correct
27 Correct 41 ms 8000 KB Output is correct
28 Correct 52 ms 7940 KB Output is correct
29 Correct 37 ms 8160 KB Output is correct
30 Correct 30 ms 8052 KB Output is correct
31 Correct 5 ms 1364 KB Output is correct
32 Correct 5 ms 1364 KB Output is correct
33 Correct 3 ms 1364 KB Output is correct
34 Correct 5 ms 1416 KB Output is correct
35 Correct 28 ms 3660 KB Output is correct
36 Correct 36 ms 3924 KB Output is correct
37 Correct 46 ms 4640 KB Output is correct
38 Correct 51 ms 4868 KB Output is correct
39 Correct 33 ms 4792 KB Output is correct
40 Correct 31 ms 4660 KB Output is correct
41 Correct 4 ms 980 KB Output is correct
42 Correct 3 ms 1052 KB Output is correct
43 Correct 30 ms 3404 KB Output is correct
44 Correct 31 ms 3396 KB Output is correct
45 Correct 43 ms 4280 KB Output is correct
46 Correct 49 ms 4296 KB Output is correct
47 Correct 30 ms 4368 KB Output is correct
48 Correct 40 ms 4304 KB Output is correct
49 Correct 3 ms 980 KB Output is correct
50 Correct 3 ms 980 KB Output is correct
51 Correct 68 ms 17360 KB Output is correct
52 Correct 74 ms 19384 KB Output is correct
53 Correct 103 ms 22296 KB Output is correct
54 Correct 104 ms 22220 KB Output is correct
55 Correct 78 ms 21916 KB Output is correct
56 Correct 102 ms 21968 KB Output is correct
57 Correct 13 ms 4920 KB Output is correct
58 Correct 13 ms 4936 KB Output is correct
59 Correct 13 ms 4836 KB Output is correct
60 Correct 13 ms 4820 KB Output is correct
61 Correct 105 ms 11280 KB Output is correct
62 Correct 70 ms 11372 KB Output is correct
63 Correct 110 ms 13748 KB Output is correct
64 Correct 117 ms 13984 KB Output is correct
65 Correct 89 ms 13768 KB Output is correct
66 Correct 90 ms 13512 KB Output is correct
67 Correct 13 ms 3156 KB Output is correct
68 Correct 13 ms 3120 KB Output is correct
69 Correct 83 ms 10204 KB Output is correct
70 Correct 74 ms 10164 KB Output is correct
71 Correct 126 ms 13188 KB Output is correct
72 Correct 148 ms 13140 KB Output is correct
73 Correct 97 ms 12584 KB Output is correct
74 Correct 91 ms 12564 KB Output is correct
75 Correct 14 ms 3008 KB Output is correct
76 Correct 14 ms 3028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 27 ms 7056 KB Output is correct
52 Correct 28 ms 7068 KB Output is correct
53 Correct 41 ms 8000 KB Output is correct
54 Correct 52 ms 7940 KB Output is correct
55 Correct 37 ms 8160 KB Output is correct
56 Correct 30 ms 8052 KB Output is correct
57 Correct 5 ms 1364 KB Output is correct
58 Correct 5 ms 1364 KB Output is correct
59 Correct 3 ms 1364 KB Output is correct
60 Correct 5 ms 1416 KB Output is correct
61 Correct 28 ms 3660 KB Output is correct
62 Correct 36 ms 3924 KB Output is correct
63 Correct 46 ms 4640 KB Output is correct
64 Correct 51 ms 4868 KB Output is correct
65 Correct 33 ms 4792 KB Output is correct
66 Correct 31 ms 4660 KB Output is correct
67 Correct 4 ms 980 KB Output is correct
68 Correct 3 ms 1052 KB Output is correct
69 Correct 30 ms 3404 KB Output is correct
70 Correct 31 ms 3396 KB Output is correct
71 Correct 43 ms 4280 KB Output is correct
72 Correct 49 ms 4296 KB Output is correct
73 Correct 30 ms 4368 KB Output is correct
74 Correct 40 ms 4304 KB Output is correct
75 Correct 3 ms 980 KB Output is correct
76 Correct 3 ms 980 KB Output is correct
77 Correct 68 ms 17360 KB Output is correct
78 Correct 74 ms 19384 KB Output is correct
79 Correct 103 ms 22296 KB Output is correct
80 Correct 104 ms 22220 KB Output is correct
81 Correct 78 ms 21916 KB Output is correct
82 Correct 102 ms 21968 KB Output is correct
83 Correct 13 ms 4920 KB Output is correct
84 Correct 13 ms 4936 KB Output is correct
85 Correct 13 ms 4836 KB Output is correct
86 Correct 13 ms 4820 KB Output is correct
87 Correct 105 ms 11280 KB Output is correct
88 Correct 70 ms 11372 KB Output is correct
89 Correct 110 ms 13748 KB Output is correct
90 Correct 117 ms 13984 KB Output is correct
91 Correct 89 ms 13768 KB Output is correct
92 Correct 90 ms 13512 KB Output is correct
93 Correct 13 ms 3156 KB Output is correct
94 Correct 13 ms 3120 KB Output is correct
95 Correct 83 ms 10204 KB Output is correct
96 Correct 74 ms 10164 KB Output is correct
97 Correct 126 ms 13188 KB Output is correct
98 Correct 148 ms 13140 KB Output is correct
99 Correct 97 ms 12584 KB Output is correct
100 Correct 91 ms 12564 KB Output is correct
101 Correct 14 ms 3008 KB Output is correct
102 Correct 14 ms 3028 KB Output is correct
103 Correct 84 ms 20208 KB Output is correct
104 Correct 74 ms 20132 KB Output is correct
105 Correct 120 ms 26732 KB Output is correct
106 Correct 128 ms 26676 KB Output is correct
107 Correct 89 ms 25484 KB Output is correct
108 Correct 95 ms 25492 KB Output is correct
109 Correct 14 ms 5448 KB Output is correct
110 Correct 14 ms 5472 KB Output is correct
111 Correct 14 ms 5468 KB Output is correct
112 Correct 14 ms 5524 KB Output is correct
113 Correct 74 ms 12332 KB Output is correct
114 Correct 83 ms 12008 KB Output is correct
115 Incorrect 133 ms 18576 KB Output isn't correct
116 Halted 0 ms 0 KB -