Submission #545931

# Submission time Handle Problem Language Result Execution time Memory
545931 2022-04-05T16:12:20 Z rainboy Magic Tree (CEOI19_magictree) C
100 / 100
220 ms 29168 KB
#include <stdio.h>

#define N	100000
#define L	17	/* L = ceil(log2(100000)) */
#define N_	(N * (L + 1))

long long max(long long a, long long b) { return a > b ? a : b; }

int ll[1 + N_], rr[1 + N_], _; long long sum[1 + N_];

int update(int t, int l, int r, int i, int x) {
	int m;

	if (t == 0)
		t = ++_;
	sum[t] += x;
	if (r - l > 1) {
		m = (l + r) / 2;
		if (i < m)
			ll[t] = update(ll[t], l, m, i, x);
		else
			rr[t] = update(rr[t], m, r, i, x);
	}
	return t;
}

int x;

int update_(int t, int l, int r, int i) {
	int m;

	if (r <= i || t == 0)
		return t;
	if (l >= i && x >= sum[t]) {
		x -= sum[t];
		return 0;
	}
	if (r - l == 1) {
		if (x >= sum[t]) {
			x -= sum[t];
			return 0;
		} else {
			sum[t] -= x, x = 0;
			return t;
		}
	}
	m = (l + r) / 2;
	ll[t] = update_(ll[t], l, m, i);
	if (x > 0)
		rr[t] = update_(rr[t], m, r, i);
	if ((sum[t] = sum[ll[t]] + sum[rr[t]]) == 0)
		t = 0;
	return t;
}

int merge(int t1, int t2) {
	if (t1 == 0)
		return t2;
	if (t2 == 0)
		return t1;
	sum[t1] += sum[t2], ll[t1] = merge(ll[t1], ll[t2]), rr[t1] = merge(rr[t1], rr[t2]);
	return t1;
}

int main() {
	static int pp[N], hh[N], ww[N], tt[N];
	int n, m, k, i;

	scanf("%d%d%d", &n, &m, &k);
	for (i = 1; i < n; i++)
		scanf("%d", &pp[i]), pp[i]--;
	while (m--) {
		int h, w;

		scanf("%d%d%d", &i, &h, &w), i--, h--;
		hh[i] = h, ww[i] = w;
	}
	for (i = n - 1; i > 0; i--) {
		if (ww[i]) {
			tt[i] = update(tt[i], 0, k, hh[i], ww[i]);
			x = ww[i], tt[i] = update_(tt[i], 0, k, hh[i] + 1);
		}
		tt[pp[i]] = merge(tt[pp[i]], tt[i]);
	}
	printf("%lld\n", sum[tt[0]]);
	return 0;
}

Compilation message

magictree.c: In function 'main':
magictree.c:69:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |  scanf("%d%d%d", &n, &m, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
magictree.c:71:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |   scanf("%d", &pp[i]), pp[i]--;
      |   ^~~~~~~~~~~~~~~~~~~
magictree.c:75:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |   scanf("%d%d%d", &i, &h, &w), i--, h--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 288 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 9856 KB Output is correct
2 Correct 41 ms 7672 KB Output is correct
3 Correct 220 ms 29168 KB Output is correct
4 Correct 138 ms 28820 KB Output is correct
5 Correct 182 ms 28996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 300 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 75 ms 6200 KB Output is correct
5 Correct 77 ms 6132 KB Output is correct
6 Correct 89 ms 16332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 5524 KB Output is correct
2 Correct 48 ms 4640 KB Output is correct
3 Correct 47 ms 4504 KB Output is correct
4 Correct 43 ms 6424 KB Output is correct
5 Correct 44 ms 3992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 288 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 65 ms 8852 KB Output is correct
11 Correct 73 ms 7620 KB Output is correct
12 Correct 48 ms 4880 KB Output is correct
13 Correct 54 ms 10552 KB Output is correct
14 Correct 69 ms 3340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 852 KB Output is correct
2 Correct 14 ms 2528 KB Output is correct
3 Correct 14 ms 2588 KB Output is correct
4 Correct 19 ms 2672 KB Output is correct
5 Correct 12 ms 2348 KB Output is correct
6 Correct 21 ms 2620 KB Output is correct
7 Correct 14 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 288 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 300 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 75 ms 6200 KB Output is correct
14 Correct 77 ms 6132 KB Output is correct
15 Correct 89 ms 16332 KB Output is correct
16 Correct 65 ms 8852 KB Output is correct
17 Correct 73 ms 7620 KB Output is correct
18 Correct 48 ms 4880 KB Output is correct
19 Correct 54 ms 10552 KB Output is correct
20 Correct 69 ms 3340 KB Output is correct
21 Correct 20 ms 3868 KB Output is correct
22 Correct 71 ms 10920 KB Output is correct
23 Correct 117 ms 15112 KB Output is correct
24 Correct 181 ms 26140 KB Output is correct
25 Correct 144 ms 28176 KB Output is correct
26 Correct 147 ms 21356 KB Output is correct
27 Correct 128 ms 15516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 288 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 57 ms 9856 KB Output is correct
11 Correct 41 ms 7672 KB Output is correct
12 Correct 220 ms 29168 KB Output is correct
13 Correct 138 ms 28820 KB Output is correct
14 Correct 182 ms 28996 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 300 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 75 ms 6200 KB Output is correct
19 Correct 77 ms 6132 KB Output is correct
20 Correct 89 ms 16332 KB Output is correct
21 Correct 49 ms 5524 KB Output is correct
22 Correct 48 ms 4640 KB Output is correct
23 Correct 47 ms 4504 KB Output is correct
24 Correct 43 ms 6424 KB Output is correct
25 Correct 44 ms 3992 KB Output is correct
26 Correct 65 ms 8852 KB Output is correct
27 Correct 73 ms 7620 KB Output is correct
28 Correct 48 ms 4880 KB Output is correct
29 Correct 54 ms 10552 KB Output is correct
30 Correct 69 ms 3340 KB Output is correct
31 Correct 4 ms 852 KB Output is correct
32 Correct 14 ms 2528 KB Output is correct
33 Correct 14 ms 2588 KB Output is correct
34 Correct 19 ms 2672 KB Output is correct
35 Correct 12 ms 2348 KB Output is correct
36 Correct 21 ms 2620 KB Output is correct
37 Correct 14 ms 2644 KB Output is correct
38 Correct 20 ms 3868 KB Output is correct
39 Correct 71 ms 10920 KB Output is correct
40 Correct 117 ms 15112 KB Output is correct
41 Correct 181 ms 26140 KB Output is correct
42 Correct 144 ms 28176 KB Output is correct
43 Correct 147 ms 21356 KB Output is correct
44 Correct 128 ms 15516 KB Output is correct
45 Correct 18 ms 3924 KB Output is correct
46 Correct 78 ms 11208 KB Output is correct
47 Correct 94 ms 15436 KB Output is correct
48 Correct 210 ms 26732 KB Output is correct
49 Correct 126 ms 28804 KB Output is correct
50 Correct 163 ms 21972 KB Output is correct
51 Correct 135 ms 16204 KB Output is correct