Submission #1031792

# Submission time Handle Problem Language Result Execution time Memory
1031792 2024-07-23T07:16:10 Z adaawf Sprinkler (JOI22_sprinkler) C++17
100 / 100
579 ms 101200 KB
#include <iostream>
#include <vector>
using namespace std;
vector<int> g[200005];
long long int f[200005][45], d[200005];
void dfs(int x, int p) {
    d[x] = p;
    for (int w : g[x]) {
        if (w == p) continue;
        dfs(w, x);
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    long long int n, l;
    cin >> n >> l;
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1, 1);
    for (int i = 1; i <= n; i++) {
        long long int x;
        cin >> x;
        f[i][0] = x;
        for (int j = 1; j <= 41; j++) f[i][j] = 1;
    }
    int q;
    cin >> q;
    for (int jj = 0; jj < q; jj++) {
        int w;
        cin >> w;
        if (w == 1) {
            long long int x, z, y;
            cin >> x >> z >> y;
            while (z >= 0) {
                f[x][z] = f[x][z] * y % l;
                x = d[x];
                z--;
            }
        }
        else {
            long long int x, z = 0, res = 1;
            cin >> x;
            while (1) {
                if (z == 41) break;
                if (x == 1) {
                    res = res * f[x][z] % l;
                    break;
                }
                res = res * f[x][z] % l * f[x][z + 1] % l;
                z++;
                x = d[x];
            }
            cout << res << '\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 5168 KB Output is correct
4 Correct 3 ms 5468 KB Output is correct
5 Correct 3 ms 5380 KB Output is correct
6 Correct 5 ms 5468 KB Output is correct
7 Correct 3 ms 5468 KB Output is correct
8 Correct 3 ms 5468 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4964 KB Output is correct
12 Correct 4 ms 4956 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 3 ms 5168 KB Output is correct
16 Correct 3 ms 4984 KB Output is correct
17 Correct 2 ms 4952 KB Output is correct
18 Correct 3 ms 4952 KB Output is correct
19 Correct 2 ms 4964 KB Output is correct
20 Correct 2 ms 5064 KB Output is correct
21 Correct 2 ms 4952 KB Output is correct
22 Correct 3 ms 4960 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 5204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 449 ms 95352 KB Output is correct
3 Correct 260 ms 95720 KB Output is correct
4 Correct 398 ms 99152 KB Output is correct
5 Correct 376 ms 95312 KB Output is correct
6 Correct 249 ms 95060 KB Output is correct
7 Correct 249 ms 95648 KB Output is correct
8 Correct 186 ms 96192 KB Output is correct
9 Correct 574 ms 100968 KB Output is correct
10 Correct 275 ms 100928 KB Output is correct
11 Correct 425 ms 95068 KB Output is correct
12 Correct 249 ms 95572 KB Output is correct
13 Correct 181 ms 96136 KB Output is correct
14 Correct 165 ms 96456 KB Output is correct
15 Correct 163 ms 96000 KB Output is correct
16 Correct 176 ms 96340 KB Output is correct
17 Correct 170 ms 96852 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 5180 KB Output is correct
20 Correct 3 ms 4952 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 449 ms 95352 KB Output is correct
3 Correct 260 ms 95720 KB Output is correct
4 Correct 398 ms 99152 KB Output is correct
5 Correct 376 ms 95312 KB Output is correct
6 Correct 249 ms 95060 KB Output is correct
7 Correct 249 ms 95648 KB Output is correct
8 Correct 186 ms 96192 KB Output is correct
9 Correct 574 ms 100968 KB Output is correct
10 Correct 275 ms 100928 KB Output is correct
11 Correct 425 ms 95068 KB Output is correct
12 Correct 249 ms 95572 KB Output is correct
13 Correct 181 ms 96136 KB Output is correct
14 Correct 165 ms 96456 KB Output is correct
15 Correct 163 ms 96000 KB Output is correct
16 Correct 176 ms 96340 KB Output is correct
17 Correct 170 ms 96852 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 5180 KB Output is correct
20 Correct 3 ms 4952 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 434 ms 95080 KB Output is correct
25 Correct 285 ms 95840 KB Output is correct
26 Correct 391 ms 101200 KB Output is correct
27 Correct 357 ms 95472 KB Output is correct
28 Correct 243 ms 95568 KB Output is correct
29 Correct 224 ms 85488 KB Output is correct
30 Correct 197 ms 94372 KB Output is correct
31 Correct 504 ms 98304 KB Output is correct
32 Correct 274 ms 98896 KB Output is correct
33 Correct 441 ms 89868 KB Output is correct
34 Correct 246 ms 84056 KB Output is correct
35 Correct 2 ms 4956 KB Output is correct
36 Correct 2 ms 4956 KB Output is correct
37 Correct 2 ms 4956 KB Output is correct
38 Correct 2 ms 4956 KB Output is correct
39 Correct 2 ms 4980 KB Output is correct
40 Correct 2 ms 4956 KB Output is correct
41 Correct 2 ms 4956 KB Output is correct
42 Correct 2 ms 4956 KB Output is correct
43 Correct 2 ms 4956 KB Output is correct
44 Correct 2 ms 4956 KB Output is correct
45 Correct 2 ms 4956 KB Output is correct
46 Correct 2 ms 4956 KB Output is correct
47 Correct 2 ms 4956 KB Output is correct
48 Correct 2 ms 4956 KB Output is correct
49 Correct 3 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4956 KB Output is correct
2 Correct 579 ms 90260 KB Output is correct
3 Correct 516 ms 97516 KB Output is correct
4 Correct 463 ms 97104 KB Output is correct
5 Correct 399 ms 92440 KB Output is correct
6 Correct 256 ms 92608 KB Output is correct
7 Correct 241 ms 93028 KB Output is correct
8 Correct 184 ms 93380 KB Output is correct
9 Correct 535 ms 96376 KB Output is correct
10 Correct 568 ms 98168 KB Output is correct
11 Correct 446 ms 92188 KB Output is correct
12 Correct 450 ms 93012 KB Output is correct
13 Correct 305 ms 94036 KB Output is correct
14 Correct 277 ms 94348 KB Output is correct
15 Correct 3 ms 5212 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 549 ms 94812 KB Output is correct
3 Correct 528 ms 94056 KB Output is correct
4 Correct 442 ms 97616 KB Output is correct
5 Correct 400 ms 94120 KB Output is correct
6 Correct 256 ms 94212 KB Output is correct
7 Correct 244 ms 94016 KB Output is correct
8 Correct 186 ms 94252 KB Output is correct
9 Correct 564 ms 100276 KB Output is correct
10 Correct 542 ms 98792 KB Output is correct
11 Correct 494 ms 94708 KB Output is correct
12 Correct 500 ms 93380 KB Output is correct
13 Correct 317 ms 94032 KB Output is correct
14 Correct 349 ms 94544 KB Output is correct
15 Correct 2 ms 4952 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4968 KB Output is correct
19 Correct 4 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 5168 KB Output is correct
4 Correct 3 ms 5468 KB Output is correct
5 Correct 3 ms 5380 KB Output is correct
6 Correct 5 ms 5468 KB Output is correct
7 Correct 3 ms 5468 KB Output is correct
8 Correct 3 ms 5468 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4964 KB Output is correct
12 Correct 4 ms 4956 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 3 ms 5168 KB Output is correct
16 Correct 3 ms 4984 KB Output is correct
17 Correct 2 ms 4952 KB Output is correct
18 Correct 3 ms 4952 KB Output is correct
19 Correct 2 ms 4964 KB Output is correct
20 Correct 2 ms 5064 KB Output is correct
21 Correct 2 ms 4952 KB Output is correct
22 Correct 3 ms 4960 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 5204 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Correct 449 ms 95352 KB Output is correct
31 Correct 260 ms 95720 KB Output is correct
32 Correct 398 ms 99152 KB Output is correct
33 Correct 376 ms 95312 KB Output is correct
34 Correct 249 ms 95060 KB Output is correct
35 Correct 249 ms 95648 KB Output is correct
36 Correct 186 ms 96192 KB Output is correct
37 Correct 574 ms 100968 KB Output is correct
38 Correct 275 ms 100928 KB Output is correct
39 Correct 425 ms 95068 KB Output is correct
40 Correct 249 ms 95572 KB Output is correct
41 Correct 181 ms 96136 KB Output is correct
42 Correct 165 ms 96456 KB Output is correct
43 Correct 163 ms 96000 KB Output is correct
44 Correct 176 ms 96340 KB Output is correct
45 Correct 170 ms 96852 KB Output is correct
46 Correct 2 ms 4956 KB Output is correct
47 Correct 2 ms 5180 KB Output is correct
48 Correct 3 ms 4952 KB Output is correct
49 Correct 2 ms 4956 KB Output is correct
50 Correct 2 ms 4956 KB Output is correct
51 Correct 2 ms 4956 KB Output is correct
52 Correct 434 ms 95080 KB Output is correct
53 Correct 285 ms 95840 KB Output is correct
54 Correct 391 ms 101200 KB Output is correct
55 Correct 357 ms 95472 KB Output is correct
56 Correct 243 ms 95568 KB Output is correct
57 Correct 224 ms 85488 KB Output is correct
58 Correct 197 ms 94372 KB Output is correct
59 Correct 504 ms 98304 KB Output is correct
60 Correct 274 ms 98896 KB Output is correct
61 Correct 441 ms 89868 KB Output is correct
62 Correct 246 ms 84056 KB Output is correct
63 Correct 2 ms 4956 KB Output is correct
64 Correct 2 ms 4956 KB Output is correct
65 Correct 2 ms 4956 KB Output is correct
66 Correct 2 ms 4956 KB Output is correct
67 Correct 2 ms 4980 KB Output is correct
68 Correct 2 ms 4956 KB Output is correct
69 Correct 2 ms 4956 KB Output is correct
70 Correct 2 ms 4956 KB Output is correct
71 Correct 2 ms 4956 KB Output is correct
72 Correct 2 ms 4956 KB Output is correct
73 Correct 2 ms 4956 KB Output is correct
74 Correct 2 ms 4956 KB Output is correct
75 Correct 2 ms 4956 KB Output is correct
76 Correct 2 ms 4956 KB Output is correct
77 Correct 3 ms 4956 KB Output is correct
78 Correct 4 ms 4956 KB Output is correct
79 Correct 579 ms 90260 KB Output is correct
80 Correct 516 ms 97516 KB Output is correct
81 Correct 463 ms 97104 KB Output is correct
82 Correct 399 ms 92440 KB Output is correct
83 Correct 256 ms 92608 KB Output is correct
84 Correct 241 ms 93028 KB Output is correct
85 Correct 184 ms 93380 KB Output is correct
86 Correct 535 ms 96376 KB Output is correct
87 Correct 568 ms 98168 KB Output is correct
88 Correct 446 ms 92188 KB Output is correct
89 Correct 450 ms 93012 KB Output is correct
90 Correct 305 ms 94036 KB Output is correct
91 Correct 277 ms 94348 KB Output is correct
92 Correct 3 ms 5212 KB Output is correct
93 Correct 2 ms 4956 KB Output is correct
94 Correct 2 ms 4956 KB Output is correct
95 Correct 2 ms 4956 KB Output is correct
96 Correct 2 ms 4952 KB Output is correct
97 Correct 2 ms 4956 KB Output is correct
98 Correct 549 ms 94812 KB Output is correct
99 Correct 528 ms 94056 KB Output is correct
100 Correct 442 ms 97616 KB Output is correct
101 Correct 400 ms 94120 KB Output is correct
102 Correct 256 ms 94212 KB Output is correct
103 Correct 244 ms 94016 KB Output is correct
104 Correct 186 ms 94252 KB Output is correct
105 Correct 564 ms 100276 KB Output is correct
106 Correct 542 ms 98792 KB Output is correct
107 Correct 494 ms 94708 KB Output is correct
108 Correct 500 ms 93380 KB Output is correct
109 Correct 317 ms 94032 KB Output is correct
110 Correct 349 ms 94544 KB Output is correct
111 Correct 2 ms 4952 KB Output is correct
112 Correct 2 ms 4952 KB Output is correct
113 Correct 2 ms 4956 KB Output is correct
114 Correct 2 ms 4968 KB Output is correct
115 Correct 4 ms 4952 KB Output is correct
116 Correct 468 ms 93152 KB Output is correct
117 Correct 466 ms 95720 KB Output is correct
118 Correct 491 ms 100964 KB Output is correct
119 Correct 414 ms 95584 KB Output is correct
120 Correct 254 ms 95060 KB Output is correct
121 Correct 260 ms 95828 KB Output is correct
122 Correct 201 ms 96144 KB Output is correct
123 Correct 555 ms 100292 KB Output is correct
124 Correct 564 ms 99156 KB Output is correct
125 Correct 465 ms 94252 KB Output is correct
126 Correct 457 ms 95568 KB Output is correct
127 Correct 489 ms 96040 KB Output is correct
128 Correct 301 ms 96852 KB Output is correct
129 Correct 327 ms 97296 KB Output is correct