Submission #781034

# Submission time Handle Problem Language Result Execution time Memory
781034 2023-07-12T16:14:45 Z rainboy Vinjete (COI22_vinjete) C
40 / 100
43 ms 15008 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];
	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]++;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 1 ms 436 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 428 KB Output is correct
5 Correct 1 ms 548 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 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 1 ms 340 KB Output is correct
13 Correct 1 ms 428 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 292 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 2 ms 432 KB Output is correct
18 Correct 2 ms 432 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 432 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 1 ms 436 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 428 KB Output is correct
5 Correct 1 ms 548 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 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 1 ms 340 KB Output is correct
13 Correct 1 ms 428 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 292 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 2 ms 432 KB Output is correct
18 Correct 2 ms 432 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 432 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 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 1 ms 468 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 2 ms 536 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 560 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 596 KB Output is correct
35 Correct 1 ms 432 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 1 ms 428 KB Output is correct
40 Correct 1 ms 436 KB Output is correct
41 Correct 1 ms 432 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 396 KB Output is correct
44 Correct 1 ms 432 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 2 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 436 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 1 ms 436 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 428 KB Output is correct
5 Correct 1 ms 548 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 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 1 ms 340 KB Output is correct
13 Correct 1 ms 428 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 292 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 2 ms 432 KB Output is correct
18 Correct 2 ms 432 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 432 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 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 28 ms 7856 KB Output is correct
26 Correct 30 ms 7876 KB Output is correct
27 Correct 38 ms 8844 KB Output is correct
28 Correct 37 ms 8904 KB Output is correct
29 Correct 30 ms 9052 KB Output is correct
30 Correct 30 ms 8972 KB Output is correct
31 Correct 4 ms 1492 KB Output is correct
32 Correct 4 ms 1452 KB Output is correct
33 Correct 3 ms 1492 KB Output is correct
34 Correct 3 ms 1492 KB Output is correct
35 Correct 29 ms 4436 KB Output is correct
36 Correct 43 ms 4724 KB Output is correct
37 Correct 43 ms 5436 KB Output is correct
38 Correct 43 ms 5708 KB Output is correct
39 Correct 33 ms 5836 KB Output is correct
40 Correct 31 ms 5552 KB Output is correct
41 Correct 3 ms 1108 KB Output is correct
42 Correct 4 ms 1108 KB Output is correct
43 Correct 29 ms 4280 KB Output is correct
44 Correct 31 ms 4300 KB Output is correct
45 Correct 42 ms 5192 KB Output is correct
46 Correct 42 ms 5276 KB Output is correct
47 Correct 33 ms 5196 KB Output is correct
48 Correct 32 ms 5296 KB Output is correct
49 Correct 4 ms 980 KB Output is correct
50 Correct 4 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 1 ms 436 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 428 KB Output is correct
5 Correct 1 ms 548 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 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 1 ms 340 KB Output is correct
13 Correct 1 ms 428 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 292 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 2 ms 432 KB Output is correct
18 Correct 2 ms 432 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 432 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 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 28 ms 7856 KB Output is correct
26 Correct 30 ms 7876 KB Output is correct
27 Correct 38 ms 8844 KB Output is correct
28 Correct 37 ms 8904 KB Output is correct
29 Correct 30 ms 9052 KB Output is correct
30 Correct 30 ms 8972 KB Output is correct
31 Correct 4 ms 1492 KB Output is correct
32 Correct 4 ms 1452 KB Output is correct
33 Correct 3 ms 1492 KB Output is correct
34 Correct 3 ms 1492 KB Output is correct
35 Correct 29 ms 4436 KB Output is correct
36 Correct 43 ms 4724 KB Output is correct
37 Correct 43 ms 5436 KB Output is correct
38 Correct 43 ms 5708 KB Output is correct
39 Correct 33 ms 5836 KB Output is correct
40 Correct 31 ms 5552 KB Output is correct
41 Correct 3 ms 1108 KB Output is correct
42 Correct 4 ms 1108 KB Output is correct
43 Correct 29 ms 4280 KB Output is correct
44 Correct 31 ms 4300 KB Output is correct
45 Correct 42 ms 5192 KB Output is correct
46 Correct 42 ms 5276 KB Output is correct
47 Correct 33 ms 5196 KB Output is correct
48 Correct 32 ms 5296 KB Output is correct
49 Correct 4 ms 980 KB Output is correct
50 Correct 4 ms 980 KB Output is correct
51 Runtime error 31 ms 15008 KB Execution killed with signal 11
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 1 ms 436 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 428 KB Output is correct
5 Correct 1 ms 548 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 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 1 ms 340 KB Output is correct
13 Correct 1 ms 428 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 292 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 2 ms 432 KB Output is correct
18 Correct 2 ms 432 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 432 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 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 1 ms 468 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 2 ms 536 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 560 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 596 KB Output is correct
35 Correct 1 ms 432 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 1 ms 428 KB Output is correct
40 Correct 1 ms 436 KB Output is correct
41 Correct 1 ms 432 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 396 KB Output is correct
44 Correct 1 ms 432 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 2 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 436 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 28 ms 7856 KB Output is correct
52 Correct 30 ms 7876 KB Output is correct
53 Correct 38 ms 8844 KB Output is correct
54 Correct 37 ms 8904 KB Output is correct
55 Correct 30 ms 9052 KB Output is correct
56 Correct 30 ms 8972 KB Output is correct
57 Correct 4 ms 1492 KB Output is correct
58 Correct 4 ms 1452 KB Output is correct
59 Correct 3 ms 1492 KB Output is correct
60 Correct 3 ms 1492 KB Output is correct
61 Correct 29 ms 4436 KB Output is correct
62 Correct 43 ms 4724 KB Output is correct
63 Correct 43 ms 5436 KB Output is correct
64 Correct 43 ms 5708 KB Output is correct
65 Correct 33 ms 5836 KB Output is correct
66 Correct 31 ms 5552 KB Output is correct
67 Correct 3 ms 1108 KB Output is correct
68 Correct 4 ms 1108 KB Output is correct
69 Correct 29 ms 4280 KB Output is correct
70 Correct 31 ms 4300 KB Output is correct
71 Correct 42 ms 5192 KB Output is correct
72 Correct 42 ms 5276 KB Output is correct
73 Correct 33 ms 5196 KB Output is correct
74 Correct 32 ms 5296 KB Output is correct
75 Correct 4 ms 980 KB Output is correct
76 Correct 4 ms 980 KB Output is correct
77 Runtime error 31 ms 15008 KB Execution killed with signal 11
78 Halted 0 ms 0 KB -