# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
568077 | 2022-05-24T15:42:08 Z | lovemathboy | Sprinkler (JOI22_sprinkler) | C++14 | 1755 ms | 103160 KB |
#include <bits/stdc++.h> using namespace std; int n, mod, q; vector<vector<long long> > a; vector<vector<int> > adj; vector<int> p; void root(int x, int par) { p[x] = par; for (int i = 0; i < adj[x].size(); i++) { int v = adj[x][i]; if (v != par) root(v, x); } } int main() { scanf("%d %d", &n, &mod); a.resize(n+1); adj.resize(n+1); p.resize(n+1, -1); for (int i = 0; i <= n; i++) { a[i].resize(41, 1); } int i1, i2, i3; for (int i = 0; i < n-1; i++) { scanf("%d %d", &i1, &i2); adj[i1].push_back(i2); adj[i2].push_back(i1); } root(1, -1); for (int i = 1; i <= n; i++) scanf("%lld", &a[i][0]); scanf("%d", &q); int v, w, d; while (q--) { scanf("%d", &i1); if (i1 == 1) { scanf("%d %d %d", &v, &d, &w); while (p[v] != -1 && d > 0) { a[v][d] = (a[v][d] * w) % mod; a[v][d - 1] = (a[v][d - 1] * w) % mod; d--; v = p[v]; } for (int i = 0; i <= d; i++) a[v][i] = (a[v][i] * w) % mod; } else { scanf("%d", &v); long long sum = a[v][0] % mod; v = p[v]; int cnt = 1; while (v != -1 && cnt <= 40) { sum = (sum * a[v][cnt]) % mod; v = p[v]; cnt++; } printf("%lld\n", sum); } } return 0; }
Compilation message
# | 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 | 2 ms | 724 KB | Output is correct |
5 | Correct | 2 ms | 728 KB | Output is correct |
6 | Correct | 2 ms | 740 KB | Output is correct |
7 | Correct | 2 ms | 724 KB | Output is correct |
8 | Correct | 3 ms | 724 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 | 308 KB | Output is correct |
18 | Correct | 1 ms | 304 KB | Output is correct |
19 | Correct | 1 ms | 300 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 1 ms | 304 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 | 308 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 | 836 ms | 94160 KB | Output is correct |
3 | Correct | 582 ms | 94720 KB | Output is correct |
4 | Correct | 761 ms | 100116 KB | Output is correct |
5 | Correct | 685 ms | 94028 KB | Output is correct |
6 | Correct | 509 ms | 92340 KB | Output is correct |
7 | Correct | 529 ms | 94680 KB | Output is correct |
8 | Correct | 403 ms | 92464 KB | Output is correct |
9 | Correct | 941 ms | 103160 KB | Output is correct |
10 | Correct | 640 ms | 102812 KB | Output is correct |
11 | Correct | 861 ms | 92592 KB | Output is correct |
12 | Correct | 597 ms | 91852 KB | Output is correct |
13 | Correct | 371 ms | 95028 KB | Output is correct |
14 | Correct | 394 ms | 95512 KB | Output is correct |
15 | Correct | 353 ms | 84904 KB | Output is correct |
16 | Correct | 395 ms | 93280 KB | Output is correct |
17 | Correct | 427 ms | 90480 KB | Output is correct |
18 | Correct | 1 ms | 300 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 2 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 304 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 836 ms | 94160 KB | Output is correct |
3 | Correct | 582 ms | 94720 KB | Output is correct |
4 | Correct | 761 ms | 100116 KB | Output is correct |
5 | Correct | 685 ms | 94028 KB | Output is correct |
6 | Correct | 509 ms | 92340 KB | Output is correct |
7 | Correct | 529 ms | 94680 KB | Output is correct |
8 | Correct | 403 ms | 92464 KB | Output is correct |
9 | Correct | 941 ms | 103160 KB | Output is correct |
10 | Correct | 640 ms | 102812 KB | Output is correct |
11 | Correct | 861 ms | 92592 KB | Output is correct |
12 | Correct | 597 ms | 91852 KB | Output is correct |
13 | Correct | 371 ms | 95028 KB | Output is correct |
14 | Correct | 394 ms | 95512 KB | Output is correct |
15 | Correct | 353 ms | 84904 KB | Output is correct |
16 | Correct | 395 ms | 93280 KB | Output is correct |
17 | Correct | 427 ms | 90480 KB | Output is correct |
18 | Correct | 1 ms | 300 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 2 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 304 KB | Output is correct |
23 | Correct | 1 ms | 212 KB | Output is correct |
24 | Correct | 1045 ms | 94160 KB | Output is correct |
25 | Correct | 702 ms | 94276 KB | Output is correct |
26 | Correct | 874 ms | 102952 KB | Output is correct |
27 | Correct | 825 ms | 93832 KB | Output is correct |
28 | Correct | 577 ms | 94444 KB | Output is correct |
29 | Correct | 543 ms | 94236 KB | Output is correct |
30 | Correct | 412 ms | 94444 KB | Output is correct |
31 | Correct | 931 ms | 100096 KB | Output is correct |
32 | Correct | 662 ms | 102136 KB | Output is correct |
33 | Correct | 936 ms | 94048 KB | Output is correct |
34 | Correct | 637 ms | 94052 KB | Output is correct |
35 | Correct | 1 ms | 212 KB | Output is correct |
36 | Correct | 1 ms | 212 KB | Output is correct |
37 | Correct | 1 ms | 308 KB | Output is correct |
38 | Correct | 1 ms | 304 KB | Output is correct |
39 | Correct | 1 ms | 212 KB | Output is correct |
40 | Correct | 1 ms | 212 KB | Output is correct |
41 | Correct | 2 ms | 212 KB | Output is correct |
42 | Correct | 1 ms | 308 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 | 212 KB | Output is correct |
46 | Correct | 1 ms | 304 KB | Output is correct |
47 | Correct | 1 ms | 212 KB | Output is correct |
48 | Correct | 1 ms | 212 KB | Output is correct |
49 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1201 ms | 99460 KB | Output is correct |
3 | Correct | 1755 ms | 97852 KB | Output is correct |
4 | Correct | 972 ms | 98088 KB | Output is correct |
5 | Correct | 819 ms | 91144 KB | Output is correct |
6 | Correct | 531 ms | 90908 KB | Output is correct |
7 | Correct | 474 ms | 91176 KB | Output is correct |
8 | Correct | 373 ms | 91600 KB | Output is correct |
9 | Correct | 968 ms | 97496 KB | Output is correct |
10 | Correct | 1582 ms | 99408 KB | Output is correct |
11 | Correct | 862 ms | 90784 KB | Output is correct |
12 | Correct | 1226 ms | 91540 KB | Output is correct |
13 | Correct | 732 ms | 92056 KB | Output is correct |
14 | Correct | 800 ms | 93076 KB | Output is correct |
15 | Correct | 1 ms | 300 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 | 304 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 956 ms | 98900 KB | Output is correct |
3 | Correct | 1574 ms | 96548 KB | Output is correct |
4 | Correct | 967 ms | 98056 KB | Output is correct |
5 | Correct | 842 ms | 92896 KB | Output is correct |
6 | Correct | 549 ms | 92652 KB | Output is correct |
7 | Correct | 515 ms | 92536 KB | Output is correct |
8 | Correct | 384 ms | 93052 KB | Output is correct |
9 | Correct | 910 ms | 101960 KB | Output is correct |
10 | Correct | 1590 ms | 100004 KB | Output is correct |
11 | Correct | 776 ms | 93488 KB | Output is correct |
12 | Correct | 1081 ms | 91844 KB | Output is correct |
13 | Correct | 688 ms | 92892 KB | Output is correct |
14 | Correct | 821 ms | 93256 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 | 300 KB | Output is correct |
19 | Correct | 1 ms | 212 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 | 2 ms | 724 KB | Output is correct |
5 | Correct | 2 ms | 728 KB | Output is correct |
6 | Correct | 2 ms | 740 KB | Output is correct |
7 | Correct | 2 ms | 724 KB | Output is correct |
8 | Correct | 3 ms | 724 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 | 308 KB | Output is correct |
18 | Correct | 1 ms | 304 KB | Output is correct |
19 | Correct | 1 ms | 300 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 1 ms | 304 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 | 308 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 | 836 ms | 94160 KB | Output is correct |
31 | Correct | 582 ms | 94720 KB | Output is correct |
32 | Correct | 761 ms | 100116 KB | Output is correct |
33 | Correct | 685 ms | 94028 KB | Output is correct |
34 | Correct | 509 ms | 92340 KB | Output is correct |
35 | Correct | 529 ms | 94680 KB | Output is correct |
36 | Correct | 403 ms | 92464 KB | Output is correct |
37 | Correct | 941 ms | 103160 KB | Output is correct |
38 | Correct | 640 ms | 102812 KB | Output is correct |
39 | Correct | 861 ms | 92592 KB | Output is correct |
40 | Correct | 597 ms | 91852 KB | Output is correct |
41 | Correct | 371 ms | 95028 KB | Output is correct |
42 | Correct | 394 ms | 95512 KB | Output is correct |
43 | Correct | 353 ms | 84904 KB | Output is correct |
44 | Correct | 395 ms | 93280 KB | Output is correct |
45 | Correct | 427 ms | 90480 KB | Output is correct |
46 | Correct | 1 ms | 300 KB | Output is correct |
47 | Correct | 1 ms | 212 KB | Output is correct |
48 | Correct | 1 ms | 212 KB | Output is correct |
49 | Correct | 2 ms | 212 KB | Output is correct |
50 | Correct | 1 ms | 304 KB | Output is correct |
51 | Correct | 1 ms | 212 KB | Output is correct |
52 | Correct | 1045 ms | 94160 KB | Output is correct |
53 | Correct | 702 ms | 94276 KB | Output is correct |
54 | Correct | 874 ms | 102952 KB | Output is correct |
55 | Correct | 825 ms | 93832 KB | Output is correct |
56 | Correct | 577 ms | 94444 KB | Output is correct |
57 | Correct | 543 ms | 94236 KB | Output is correct |
58 | Correct | 412 ms | 94444 KB | Output is correct |
59 | Correct | 931 ms | 100096 KB | Output is correct |
60 | Correct | 662 ms | 102136 KB | Output is correct |
61 | Correct | 936 ms | 94048 KB | Output is correct |
62 | Correct | 637 ms | 94052 KB | Output is correct |
63 | Correct | 1 ms | 212 KB | Output is correct |
64 | Correct | 1 ms | 212 KB | Output is correct |
65 | Correct | 1 ms | 308 KB | Output is correct |
66 | Correct | 1 ms | 304 KB | Output is correct |
67 | Correct | 1 ms | 212 KB | Output is correct |
68 | Correct | 1 ms | 212 KB | Output is correct |
69 | Correct | 2 ms | 212 KB | Output is correct |
70 | Correct | 1 ms | 308 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 | 212 KB | Output is correct |
74 | Correct | 1 ms | 304 KB | Output is correct |
75 | Correct | 1 ms | 212 KB | Output is correct |
76 | Correct | 1 ms | 212 KB | Output is correct |
77 | Correct | 1 ms | 212 KB | Output is correct |
78 | Correct | 1 ms | 212 KB | Output is correct |
79 | Correct | 1201 ms | 99460 KB | Output is correct |
80 | Correct | 1755 ms | 97852 KB | Output is correct |
81 | Correct | 972 ms | 98088 KB | Output is correct |
82 | Correct | 819 ms | 91144 KB | Output is correct |
83 | Correct | 531 ms | 90908 KB | Output is correct |
84 | Correct | 474 ms | 91176 KB | Output is correct |
85 | Correct | 373 ms | 91600 KB | Output is correct |
86 | Correct | 968 ms | 97496 KB | Output is correct |
87 | Correct | 1582 ms | 99408 KB | Output is correct |
88 | Correct | 862 ms | 90784 KB | Output is correct |
89 | Correct | 1226 ms | 91540 KB | Output is correct |
90 | Correct | 732 ms | 92056 KB | Output is correct |
91 | Correct | 800 ms | 93076 KB | Output is correct |
92 | Correct | 1 ms | 300 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 | 304 KB | Output is correct |
96 | Correct | 1 ms | 212 KB | Output is correct |
97 | Correct | 1 ms | 212 KB | Output is correct |
98 | Correct | 956 ms | 98900 KB | Output is correct |
99 | Correct | 1574 ms | 96548 KB | Output is correct |
100 | Correct | 967 ms | 98056 KB | Output is correct |
101 | Correct | 842 ms | 92896 KB | Output is correct |
102 | Correct | 549 ms | 92652 KB | Output is correct |
103 | Correct | 515 ms | 92536 KB | Output is correct |
104 | Correct | 384 ms | 93052 KB | Output is correct |
105 | Correct | 910 ms | 101960 KB | Output is correct |
106 | Correct | 1590 ms | 100004 KB | Output is correct |
107 | Correct | 776 ms | 93488 KB | Output is correct |
108 | Correct | 1081 ms | 91844 KB | Output is correct |
109 | Correct | 688 ms | 92892 KB | Output is correct |
110 | Correct | 821 ms | 93256 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 | 300 KB | Output is correct |
115 | Correct | 1 ms | 212 KB | Output is correct |
116 | Correct | 798 ms | 91852 KB | Output is correct |
117 | Correct | 1167 ms | 94604 KB | Output is correct |
118 | Correct | 945 ms | 102256 KB | Output is correct |
119 | Correct | 834 ms | 94200 KB | Output is correct |
120 | Correct | 541 ms | 93448 KB | Output is correct |
121 | Correct | 522 ms | 94420 KB | Output is correct |
122 | Correct | 409 ms | 94472 KB | Output is correct |
123 | Correct | 916 ms | 101124 KB | Output is correct |
124 | Correct | 1542 ms | 99960 KB | Output is correct |
125 | Correct | 802 ms | 92516 KB | Output is correct |
126 | Correct | 1172 ms | 94312 KB | Output is correct |
127 | Correct | 1163 ms | 94716 KB | Output is correct |
128 | Correct | 746 ms | 94452 KB | Output is correct |
129 | Correct | 888 ms | 95756 KB | Output is correct |