답안 #781041

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781041 2023-07-12T16:19:55 Z rainboy Vinjete (COI22_vinjete) C
100 / 100
155 ms 23780 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] : (i < n_ ? st[i << 1 | 0] + st[i << 1 | 1] : 0);
}

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 1 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 0 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 1 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 0 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 2 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 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 1 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 0 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 2 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 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 1 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 1 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 1 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 1 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 1 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 0 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 1 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 0 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 2 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 30 ms 7116 KB Output is correct
26 Correct 30 ms 7120 KB Output is correct
27 Correct 42 ms 7968 KB Output is correct
28 Correct 42 ms 7960 KB Output is correct
29 Correct 32 ms 8124 KB Output is correct
30 Correct 31 ms 8156 KB Output is correct
31 Correct 6 ms 1364 KB Output is correct
32 Correct 4 ms 1364 KB Output is correct
33 Correct 4 ms 1364 KB Output is correct
34 Correct 4 ms 1364 KB Output is correct
35 Correct 31 ms 3728 KB Output is correct
36 Correct 32 ms 3920 KB Output is correct
37 Correct 46 ms 4556 KB Output is correct
38 Correct 45 ms 4788 KB Output is correct
39 Correct 35 ms 4740 KB Output is correct
40 Correct 33 ms 4672 KB Output is correct
41 Correct 4 ms 980 KB Output is correct
42 Correct 4 ms 980 KB Output is correct
43 Correct 32 ms 3404 KB Output is correct
44 Correct 32 ms 3408 KB Output is correct
45 Correct 47 ms 4368 KB Output is correct
46 Correct 46 ms 4300 KB Output is correct
47 Correct 33 ms 4320 KB Output is correct
48 Correct 33 ms 4368 KB Output is correct
49 Correct 4 ms 980 KB Output is correct
50 Correct 4 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 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 1 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 0 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 2 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 30 ms 7116 KB Output is correct
26 Correct 30 ms 7120 KB Output is correct
27 Correct 42 ms 7968 KB Output is correct
28 Correct 42 ms 7960 KB Output is correct
29 Correct 32 ms 8124 KB Output is correct
30 Correct 31 ms 8156 KB Output is correct
31 Correct 6 ms 1364 KB Output is correct
32 Correct 4 ms 1364 KB Output is correct
33 Correct 4 ms 1364 KB Output is correct
34 Correct 4 ms 1364 KB Output is correct
35 Correct 31 ms 3728 KB Output is correct
36 Correct 32 ms 3920 KB Output is correct
37 Correct 46 ms 4556 KB Output is correct
38 Correct 45 ms 4788 KB Output is correct
39 Correct 35 ms 4740 KB Output is correct
40 Correct 33 ms 4672 KB Output is correct
41 Correct 4 ms 980 KB Output is correct
42 Correct 4 ms 980 KB Output is correct
43 Correct 32 ms 3404 KB Output is correct
44 Correct 32 ms 3408 KB Output is correct
45 Correct 47 ms 4368 KB Output is correct
46 Correct 46 ms 4300 KB Output is correct
47 Correct 33 ms 4320 KB Output is correct
48 Correct 33 ms 4368 KB Output is correct
49 Correct 4 ms 980 KB Output is correct
50 Correct 4 ms 980 KB Output is correct
51 Correct 80 ms 17452 KB Output is correct
52 Correct 80 ms 17344 KB Output is correct
53 Correct 120 ms 19964 KB Output is correct
54 Correct 117 ms 19936 KB Output is correct
55 Correct 84 ms 19660 KB Output is correct
56 Correct 82 ms 19600 KB Output is correct
57 Correct 15 ms 4440 KB Output is correct
58 Correct 14 ms 4464 KB Output is correct
59 Correct 14 ms 4436 KB Output is correct
60 Correct 14 ms 4436 KB Output is correct
61 Correct 78 ms 9096 KB Output is correct
62 Correct 85 ms 9464 KB Output is correct
63 Correct 144 ms 11516 KB Output is correct
64 Correct 127 ms 11596 KB Output is correct
65 Correct 94 ms 11504 KB Output is correct
66 Correct 85 ms 11200 KB Output is correct
67 Correct 14 ms 2772 KB Output is correct
68 Correct 16 ms 2680 KB Output is correct
69 Correct 96 ms 8148 KB Output is correct
70 Correct 85 ms 8140 KB Output is correct
71 Correct 144 ms 10800 KB Output is correct
72 Correct 129 ms 10756 KB Output is correct
73 Correct 97 ms 10188 KB Output is correct
74 Correct 90 ms 10300 KB Output is correct
75 Correct 15 ms 2516 KB Output is correct
76 Correct 15 ms 2624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 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 1 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 0 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 2 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 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 1 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 1 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 1 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 1 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 30 ms 7116 KB Output is correct
52 Correct 30 ms 7120 KB Output is correct
53 Correct 42 ms 7968 KB Output is correct
54 Correct 42 ms 7960 KB Output is correct
55 Correct 32 ms 8124 KB Output is correct
56 Correct 31 ms 8156 KB Output is correct
57 Correct 6 ms 1364 KB Output is correct
58 Correct 4 ms 1364 KB Output is correct
59 Correct 4 ms 1364 KB Output is correct
60 Correct 4 ms 1364 KB Output is correct
61 Correct 31 ms 3728 KB Output is correct
62 Correct 32 ms 3920 KB Output is correct
63 Correct 46 ms 4556 KB Output is correct
64 Correct 45 ms 4788 KB Output is correct
65 Correct 35 ms 4740 KB Output is correct
66 Correct 33 ms 4672 KB Output is correct
67 Correct 4 ms 980 KB Output is correct
68 Correct 4 ms 980 KB Output is correct
69 Correct 32 ms 3404 KB Output is correct
70 Correct 32 ms 3408 KB Output is correct
71 Correct 47 ms 4368 KB Output is correct
72 Correct 46 ms 4300 KB Output is correct
73 Correct 33 ms 4320 KB Output is correct
74 Correct 33 ms 4368 KB Output is correct
75 Correct 4 ms 980 KB Output is correct
76 Correct 4 ms 980 KB Output is correct
77 Correct 80 ms 17452 KB Output is correct
78 Correct 80 ms 17344 KB Output is correct
79 Correct 120 ms 19964 KB Output is correct
80 Correct 117 ms 19936 KB Output is correct
81 Correct 84 ms 19660 KB Output is correct
82 Correct 82 ms 19600 KB Output is correct
83 Correct 15 ms 4440 KB Output is correct
84 Correct 14 ms 4464 KB Output is correct
85 Correct 14 ms 4436 KB Output is correct
86 Correct 14 ms 4436 KB Output is correct
87 Correct 78 ms 9096 KB Output is correct
88 Correct 85 ms 9464 KB Output is correct
89 Correct 144 ms 11516 KB Output is correct
90 Correct 127 ms 11596 KB Output is correct
91 Correct 94 ms 11504 KB Output is correct
92 Correct 85 ms 11200 KB Output is correct
93 Correct 14 ms 2772 KB Output is correct
94 Correct 16 ms 2680 KB Output is correct
95 Correct 96 ms 8148 KB Output is correct
96 Correct 85 ms 8140 KB Output is correct
97 Correct 144 ms 10800 KB Output is correct
98 Correct 129 ms 10756 KB Output is correct
99 Correct 97 ms 10188 KB Output is correct
100 Correct 90 ms 10300 KB Output is correct
101 Correct 15 ms 2516 KB Output is correct
102 Correct 15 ms 2624 KB Output is correct
103 Correct 80 ms 17740 KB Output is correct
104 Correct 80 ms 17708 KB Output is correct
105 Correct 150 ms 23780 KB Output is correct
106 Correct 137 ms 23580 KB Output is correct
107 Correct 97 ms 22376 KB Output is correct
108 Correct 92 ms 22448 KB Output is correct
109 Correct 15 ms 4836 KB Output is correct
110 Correct 15 ms 4948 KB Output is correct
111 Correct 18 ms 4912 KB Output is correct
112 Correct 15 ms 4848 KB Output is correct
113 Correct 87 ms 10000 KB Output is correct
114 Correct 86 ms 9688 KB Output is correct
115 Correct 141 ms 15412 KB Output is correct
116 Correct 155 ms 18656 KB Output is correct
117 Correct 102 ms 17260 KB Output is correct
118 Correct 101 ms 17024 KB Output is correct
119 Correct 20 ms 3912 KB Output is correct
120 Correct 16 ms 3892 KB Output is correct
121 Correct 85 ms 10936 KB Output is correct
122 Correct 118 ms 11048 KB Output is correct
123 Correct 151 ms 17612 KB Output is correct
124 Correct 149 ms 17688 KB Output is correct
125 Correct 112 ms 16072 KB Output is correct
126 Correct 112 ms 16204 KB Output is correct
127 Correct 16 ms 3672 KB Output is correct
128 Correct 18 ms 3660 KB Output is correct