#include <stdio.h>
#include <stdlib.h>
#define N 200000
#define D 40
#define N_ (N + D)
int *ej[N_], eo[N_];
void append(int i, int j) {
int o = eo[i]++;
if (o >= 2 && (o & o - 1) == 0)
ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
ej[i][o] = j;
}
int pp[N_];
void dfs(int p, int i) {
int o;
pp[i] = p;
for (o = eo[i]; o--; ) {
int j = ej[i][o];
if (j != p)
dfs(i, j);
}
}
int main() {
static int aa[N_][D + 1];
int n, q, md, h, i, j, d;
scanf("%d%d", &n, &md);
for (i = 0; i < n + D; i++)
ej[i] = (int *) malloc(2 * sizeof *ej[i]);
for (h = 0; h < n - 1; h++) {
scanf("%d%d", &i, &j), i--, j--;
append(i, j), append(j, i);
}
for (h = 0; h + 1 < D; h++)
append(n + h, n + h + 1), append(n + h + 1, n + h);
append(n + D - 1, 0), append(0, n + D - 1);
dfs(-1, n);
for (i = 0; i < n + D; i++)
for (d = 0; d <= D; d++)
aa[i][d] = 1;
for (i = 0; i < n; i++)
scanf("%d", &aa[i][0]);
scanf("%d", &q);
while (q--) {
int t, ans;
scanf("%d%d", &t, &i), i--;
if (t == 1) {
int x;
scanf("%d%d", &d, &x);
while (d >= 0) {
aa[i][d] = (long long) aa[i][d] * x % md;
if (d > 0)
aa[i][d - 1] = (long long) aa[i][d - 1] * x % md;
i = pp[i], d--;
}
} else {
ans = 1;
for (d = 0; d <= D; d++, i = pp[i])
ans = (long long) ans * aa[i][d] % md;
printf("%d\n", ans);
}
}
return 0;
}
Compilation message
sprinkler.c: In function 'append':
sprinkler.c:13:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
13 | if (o >= 2 && (o & o - 1) == 0)
| ~~^~~
sprinkler.c: In function 'main':
sprinkler.c:36:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | scanf("%d%d", &n, &md);
| ^~~~~~~~~~~~~~~~~~~~~~
sprinkler.c:40:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | scanf("%d%d", &i, &j), i--, j--;
| ^~~~~~~~~~~~~~~~~~~~~
sprinkler.c:51:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | scanf("%d", &aa[i][0]);
| ^~~~~~~~~~~~~~~~~~~~~~
sprinkler.c:52:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | scanf("%d", &q);
| ^~~~~~~~~~~~~~~
sprinkler.c:56:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | scanf("%d%d", &t, &i), i--;
| ^~~~~~~~~~~~~~~~~~~~~
sprinkler.c:60:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | scanf("%d%d", &d, &x);
| ^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
488 ms |
45496 KB |
Output is correct |
3 |
Correct |
361 ms |
42976 KB |
Output is correct |
4 |
Correct |
448 ms |
48444 KB |
Output is correct |
5 |
Correct |
409 ms |
44360 KB |
Output is correct |
6 |
Correct |
350 ms |
44648 KB |
Output is correct |
7 |
Correct |
340 ms |
44904 KB |
Output is correct |
8 |
Correct |
327 ms |
44572 KB |
Output is correct |
9 |
Correct |
533 ms |
51512 KB |
Output is correct |
10 |
Correct |
380 ms |
59460 KB |
Output is correct |
11 |
Correct |
501 ms |
53792 KB |
Output is correct |
12 |
Correct |
342 ms |
54184 KB |
Output is correct |
13 |
Correct |
288 ms |
54448 KB |
Output is correct |
14 |
Correct |
274 ms |
54908 KB |
Output is correct |
15 |
Correct |
275 ms |
54520 KB |
Output is correct |
16 |
Correct |
276 ms |
54856 KB |
Output is correct |
17 |
Correct |
277 ms |
55280 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 |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
488 ms |
45496 KB |
Output is correct |
3 |
Correct |
361 ms |
42976 KB |
Output is correct |
4 |
Correct |
448 ms |
48444 KB |
Output is correct |
5 |
Correct |
409 ms |
44360 KB |
Output is correct |
6 |
Correct |
350 ms |
44648 KB |
Output is correct |
7 |
Correct |
340 ms |
44904 KB |
Output is correct |
8 |
Correct |
327 ms |
44572 KB |
Output is correct |
9 |
Correct |
533 ms |
51512 KB |
Output is correct |
10 |
Correct |
380 ms |
59460 KB |
Output is correct |
11 |
Correct |
501 ms |
53792 KB |
Output is correct |
12 |
Correct |
342 ms |
54184 KB |
Output is correct |
13 |
Correct |
288 ms |
54448 KB |
Output is correct |
14 |
Correct |
274 ms |
54908 KB |
Output is correct |
15 |
Correct |
275 ms |
54520 KB |
Output is correct |
16 |
Correct |
276 ms |
54856 KB |
Output is correct |
17 |
Correct |
277 ms |
55280 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 |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
480 ms |
53756 KB |
Output is correct |
25 |
Correct |
359 ms |
54272 KB |
Output is correct |
26 |
Correct |
466 ms |
59760 KB |
Output is correct |
27 |
Correct |
411 ms |
53964 KB |
Output is correct |
28 |
Correct |
358 ms |
54476 KB |
Output is correct |
29 |
Correct |
351 ms |
54136 KB |
Output is correct |
30 |
Correct |
324 ms |
54772 KB |
Output is correct |
31 |
Correct |
532 ms |
57768 KB |
Output is correct |
32 |
Correct |
375 ms |
59468 KB |
Output is correct |
33 |
Correct |
480 ms |
53808 KB |
Output is correct |
34 |
Correct |
358 ms |
54236 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
559 ms |
48680 KB |
Output is correct |
3 |
Correct |
656 ms |
55904 KB |
Output is correct |
4 |
Correct |
522 ms |
55660 KB |
Output is correct |
5 |
Correct |
463 ms |
51020 KB |
Output is correct |
6 |
Correct |
375 ms |
51324 KB |
Output is correct |
7 |
Correct |
358 ms |
51664 KB |
Output is correct |
8 |
Correct |
337 ms |
51704 KB |
Output is correct |
9 |
Correct |
598 ms |
54820 KB |
Output is correct |
10 |
Correct |
709 ms |
56628 KB |
Output is correct |
11 |
Correct |
504 ms |
50656 KB |
Output is correct |
12 |
Correct |
597 ms |
51584 KB |
Output is correct |
13 |
Correct |
418 ms |
52520 KB |
Output is correct |
14 |
Correct |
408 ms |
52984 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
558 ms |
49364 KB |
Output is correct |
3 |
Correct |
666 ms |
54952 KB |
Output is correct |
4 |
Correct |
547 ms |
56076 KB |
Output is correct |
5 |
Correct |
465 ms |
52764 KB |
Output is correct |
6 |
Correct |
387 ms |
53156 KB |
Output is correct |
7 |
Correct |
391 ms |
52812 KB |
Output is correct |
8 |
Correct |
374 ms |
52872 KB |
Output is correct |
9 |
Correct |
611 ms |
58796 KB |
Output is correct |
10 |
Correct |
661 ms |
57284 KB |
Output is correct |
11 |
Correct |
510 ms |
53436 KB |
Output is correct |
12 |
Correct |
540 ms |
51776 KB |
Output is correct |
13 |
Correct |
418 ms |
52612 KB |
Output is correct |
14 |
Correct |
441 ms |
53096 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
488 ms |
45496 KB |
Output is correct |
31 |
Correct |
361 ms |
42976 KB |
Output is correct |
32 |
Correct |
448 ms |
48444 KB |
Output is correct |
33 |
Correct |
409 ms |
44360 KB |
Output is correct |
34 |
Correct |
350 ms |
44648 KB |
Output is correct |
35 |
Correct |
340 ms |
44904 KB |
Output is correct |
36 |
Correct |
327 ms |
44572 KB |
Output is correct |
37 |
Correct |
533 ms |
51512 KB |
Output is correct |
38 |
Correct |
380 ms |
59460 KB |
Output is correct |
39 |
Correct |
501 ms |
53792 KB |
Output is correct |
40 |
Correct |
342 ms |
54184 KB |
Output is correct |
41 |
Correct |
288 ms |
54448 KB |
Output is correct |
42 |
Correct |
274 ms |
54908 KB |
Output is correct |
43 |
Correct |
275 ms |
54520 KB |
Output is correct |
44 |
Correct |
276 ms |
54856 KB |
Output is correct |
45 |
Correct |
277 ms |
55280 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
0 ms |
212 KB |
Output is correct |
52 |
Correct |
480 ms |
53756 KB |
Output is correct |
53 |
Correct |
359 ms |
54272 KB |
Output is correct |
54 |
Correct |
466 ms |
59760 KB |
Output is correct |
55 |
Correct |
411 ms |
53964 KB |
Output is correct |
56 |
Correct |
358 ms |
54476 KB |
Output is correct |
57 |
Correct |
351 ms |
54136 KB |
Output is correct |
58 |
Correct |
324 ms |
54772 KB |
Output is correct |
59 |
Correct |
532 ms |
57768 KB |
Output is correct |
60 |
Correct |
375 ms |
59468 KB |
Output is correct |
61 |
Correct |
480 ms |
53808 KB |
Output is correct |
62 |
Correct |
358 ms |
54236 KB |
Output is correct |
63 |
Correct |
1 ms |
340 KB |
Output is correct |
64 |
Correct |
1 ms |
340 KB |
Output is correct |
65 |
Correct |
1 ms |
340 KB |
Output is correct |
66 |
Correct |
1 ms |
340 KB |
Output is correct |
67 |
Correct |
1 ms |
340 KB |
Output is correct |
68 |
Correct |
1 ms |
212 KB |
Output is correct |
69 |
Correct |
1 ms |
212 KB |
Output is correct |
70 |
Correct |
1 ms |
212 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
1 ms |
212 KB |
Output is correct |
73 |
Correct |
1 ms |
340 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
1 ms |
340 KB |
Output is correct |
77 |
Correct |
1 ms |
340 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
559 ms |
48680 KB |
Output is correct |
80 |
Correct |
656 ms |
55904 KB |
Output is correct |
81 |
Correct |
522 ms |
55660 KB |
Output is correct |
82 |
Correct |
463 ms |
51020 KB |
Output is correct |
83 |
Correct |
375 ms |
51324 KB |
Output is correct |
84 |
Correct |
358 ms |
51664 KB |
Output is correct |
85 |
Correct |
337 ms |
51704 KB |
Output is correct |
86 |
Correct |
598 ms |
54820 KB |
Output is correct |
87 |
Correct |
709 ms |
56628 KB |
Output is correct |
88 |
Correct |
504 ms |
50656 KB |
Output is correct |
89 |
Correct |
597 ms |
51584 KB |
Output is correct |
90 |
Correct |
418 ms |
52520 KB |
Output is correct |
91 |
Correct |
408 ms |
52984 KB |
Output is correct |
92 |
Correct |
1 ms |
212 KB |
Output is correct |
93 |
Correct |
1 ms |
212 KB |
Output is correct |
94 |
Correct |
1 ms |
212 KB |
Output is correct |
95 |
Correct |
1 ms |
212 KB |
Output is correct |
96 |
Correct |
1 ms |
212 KB |
Output is correct |
97 |
Correct |
0 ms |
212 KB |
Output is correct |
98 |
Correct |
558 ms |
49364 KB |
Output is correct |
99 |
Correct |
666 ms |
54952 KB |
Output is correct |
100 |
Correct |
547 ms |
56076 KB |
Output is correct |
101 |
Correct |
465 ms |
52764 KB |
Output is correct |
102 |
Correct |
387 ms |
53156 KB |
Output is correct |
103 |
Correct |
391 ms |
52812 KB |
Output is correct |
104 |
Correct |
374 ms |
52872 KB |
Output is correct |
105 |
Correct |
611 ms |
58796 KB |
Output is correct |
106 |
Correct |
661 ms |
57284 KB |
Output is correct |
107 |
Correct |
510 ms |
53436 KB |
Output is correct |
108 |
Correct |
540 ms |
51776 KB |
Output is correct |
109 |
Correct |
418 ms |
52612 KB |
Output is correct |
110 |
Correct |
441 ms |
53096 KB |
Output is correct |
111 |
Correct |
1 ms |
212 KB |
Output is correct |
112 |
Correct |
1 ms |
212 KB |
Output is correct |
113 |
Correct |
1 ms |
212 KB |
Output is correct |
114 |
Correct |
1 ms |
340 KB |
Output is correct |
115 |
Correct |
1 ms |
296 KB |
Output is correct |
116 |
Correct |
494 ms |
51860 KB |
Output is correct |
117 |
Correct |
616 ms |
54348 KB |
Output is correct |
118 |
Correct |
524 ms |
59592 KB |
Output is correct |
119 |
Correct |
482 ms |
54052 KB |
Output is correct |
120 |
Correct |
434 ms |
53840 KB |
Output is correct |
121 |
Correct |
428 ms |
54808 KB |
Output is correct |
122 |
Correct |
405 ms |
54700 KB |
Output is correct |
123 |
Correct |
567 ms |
58456 KB |
Output is correct |
124 |
Correct |
674 ms |
57716 KB |
Output is correct |
125 |
Correct |
502 ms |
52876 KB |
Output is correct |
126 |
Correct |
595 ms |
54204 KB |
Output is correct |
127 |
Correct |
630 ms |
54796 KB |
Output is correct |
128 |
Correct |
568 ms |
55372 KB |
Output is correct |
129 |
Correct |
549 ms |
55864 KB |
Output is correct |