Submission #704481

# Submission time Handle Problem Language Result Execution time Memory
704481 2023-03-02T07:33:29 Z piOOE Sprinkler (JOI22_sprinkler) C++17
100 / 100
717 ms 57272 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, MOD;
    cin >> n >> MOD;

    vector<vector<int>> adj(n);

    for (int i = 1; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        a -= 1, b -= 1;

        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    vector<int> parent(n, -1), depth(n);

    auto dfs = [&](auto self, int v) -> void {
        for (int to : adj[v]) {
            if (to != parent[v]) {
                depth[to] = depth[v] + 1;
                parent[to] = v;
                self(self, to);
            }
        }
    };

    dfs(dfs, 0);

    vector<int> h(n);

    for (int &x : h) {
        cin >> x;
    }

    int q;
    cin >> q;

    constexpr int maxD = 40;

    vector<array<int, maxD + 1>> kek(n);

    for (int i = 0; i < n; ++i) {
        fill(kek[i].begin(), kek[i].end(), 1);
    }

    for (int i = 0; i < q; ++i) {
        int t, v;
        cin >> t >> v;
        v -= 1;

        if (t == 1) {
            int dist;
            ll weight;
            cin >> dist >> weight;

            while (v != 0 && dist > 0) {
                kek[v][dist] = weight * kek[v][dist] % MOD;
                kek[v][dist - 1] = weight * kek[v][dist - 1] % MOD;
                v = parent[v];
                dist -= 1;
            }

            for (int j = 0; j <= dist; ++j) {
                kek[v][j] = kek[v][j] * weight % MOD;
            }
        } else {
            int dist = 0, ans = h[v];

            while (v != -1 && dist <= maxD) {
                ans = 1LL * ans * kek[v][dist] % MOD;
                v = parent[v];
                dist += 1;
            }

            cout << ans << '\n';
        }
    }

    return 0;
}
# 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 0 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 0 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 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 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 0 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 500 ms 49356 KB Output is correct
3 Correct 323 ms 46260 KB Output is correct
4 Correct 457 ms 53168 KB Output is correct
5 Correct 418 ms 47892 KB Output is correct
6 Correct 307 ms 47732 KB Output is correct
7 Correct 295 ms 48020 KB Output is correct
8 Correct 242 ms 48460 KB Output is correct
9 Correct 593 ms 57272 KB Output is correct
10 Correct 340 ms 53440 KB Output is correct
11 Correct 494 ms 49424 KB Output is correct
12 Correct 347 ms 46384 KB Output is correct
13 Correct 212 ms 46828 KB Output is correct
14 Correct 221 ms 46784 KB Output is correct
15 Correct 220 ms 46784 KB Output is correct
16 Correct 230 ms 46808 KB Output is correct
17 Correct 234 ms 47316 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 232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 500 ms 49356 KB Output is correct
3 Correct 323 ms 46260 KB Output is correct
4 Correct 457 ms 53168 KB Output is correct
5 Correct 418 ms 47892 KB Output is correct
6 Correct 307 ms 47732 KB Output is correct
7 Correct 295 ms 48020 KB Output is correct
8 Correct 242 ms 48460 KB Output is correct
9 Correct 593 ms 57272 KB Output is correct
10 Correct 340 ms 53440 KB Output is correct
11 Correct 494 ms 49424 KB Output is correct
12 Correct 347 ms 46384 KB Output is correct
13 Correct 212 ms 46828 KB Output is correct
14 Correct 221 ms 46784 KB Output is correct
15 Correct 220 ms 46784 KB Output is correct
16 Correct 230 ms 46808 KB Output is correct
17 Correct 234 ms 47316 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 232 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 482 ms 49444 KB Output is correct
25 Correct 341 ms 46252 KB Output is correct
26 Correct 449 ms 55368 KB Output is correct
27 Correct 427 ms 47744 KB Output is correct
28 Correct 312 ms 47892 KB Output is correct
29 Correct 290 ms 47852 KB Output is correct
30 Correct 282 ms 48448 KB Output is correct
31 Correct 567 ms 54904 KB Output is correct
32 Correct 352 ms 53504 KB Output is correct
33 Correct 475 ms 49388 KB Output is correct
34 Correct 329 ms 46092 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 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 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 212 KB Output is correct
46 Correct 1 ms 212 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 0 ms 212 KB Output is correct
2 Correct 605 ms 54536 KB Output is correct
3 Correct 672 ms 51940 KB Output is correct
4 Correct 557 ms 52628 KB Output is correct
5 Correct 468 ms 46128 KB Output is correct
6 Correct 319 ms 46284 KB Output is correct
7 Correct 300 ms 46400 KB Output is correct
8 Correct 235 ms 46944 KB Output is correct
9 Correct 587 ms 52204 KB Output is correct
10 Correct 681 ms 53160 KB Output is correct
11 Correct 529 ms 46724 KB Output is correct
12 Correct 562 ms 45900 KB Output is correct
13 Correct 407 ms 46664 KB Output is correct
14 Correct 434 ms 47412 KB Output is correct
15 Correct 0 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 0 ms 212 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 631 ms 54544 KB Output is correct
3 Correct 665 ms 50484 KB Output is correct
4 Correct 553 ms 52464 KB Output is correct
5 Correct 495 ms 47768 KB Output is correct
6 Correct 348 ms 47820 KB Output is correct
7 Correct 338 ms 47764 KB Output is correct
8 Correct 239 ms 48220 KB Output is correct
9 Correct 606 ms 56656 KB Output is correct
10 Correct 717 ms 53620 KB Output is correct
11 Correct 519 ms 49268 KB Output is correct
12 Correct 610 ms 46316 KB Output is correct
13 Correct 422 ms 46944 KB Output is correct
14 Correct 425 ms 47352 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 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 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 0 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 0 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 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 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 0 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 500 ms 49356 KB Output is correct
31 Correct 323 ms 46260 KB Output is correct
32 Correct 457 ms 53168 KB Output is correct
33 Correct 418 ms 47892 KB Output is correct
34 Correct 307 ms 47732 KB Output is correct
35 Correct 295 ms 48020 KB Output is correct
36 Correct 242 ms 48460 KB Output is correct
37 Correct 593 ms 57272 KB Output is correct
38 Correct 340 ms 53440 KB Output is correct
39 Correct 494 ms 49424 KB Output is correct
40 Correct 347 ms 46384 KB Output is correct
41 Correct 212 ms 46828 KB Output is correct
42 Correct 221 ms 46784 KB Output is correct
43 Correct 220 ms 46784 KB Output is correct
44 Correct 230 ms 46808 KB Output is correct
45 Correct 234 ms 47316 KB Output is correct
46 Correct 1 ms 212 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
50 Correct 1 ms 232 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 482 ms 49444 KB Output is correct
53 Correct 341 ms 46252 KB Output is correct
54 Correct 449 ms 55368 KB Output is correct
55 Correct 427 ms 47744 KB Output is correct
56 Correct 312 ms 47892 KB Output is correct
57 Correct 290 ms 47852 KB Output is correct
58 Correct 282 ms 48448 KB Output is correct
59 Correct 567 ms 54904 KB Output is correct
60 Correct 352 ms 53504 KB Output is correct
61 Correct 475 ms 49388 KB Output is correct
62 Correct 329 ms 46092 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 212 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 1 ms 212 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 0 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 212 KB Output is correct
74 Correct 1 ms 212 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 0 ms 212 KB Output is correct
79 Correct 605 ms 54536 KB Output is correct
80 Correct 672 ms 51940 KB Output is correct
81 Correct 557 ms 52628 KB Output is correct
82 Correct 468 ms 46128 KB Output is correct
83 Correct 319 ms 46284 KB Output is correct
84 Correct 300 ms 46400 KB Output is correct
85 Correct 235 ms 46944 KB Output is correct
86 Correct 587 ms 52204 KB Output is correct
87 Correct 681 ms 53160 KB Output is correct
88 Correct 529 ms 46724 KB Output is correct
89 Correct 562 ms 45900 KB Output is correct
90 Correct 407 ms 46664 KB Output is correct
91 Correct 434 ms 47412 KB Output is correct
92 Correct 0 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 0 ms 212 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 1 ms 212 KB Output is correct
98 Correct 631 ms 54544 KB Output is correct
99 Correct 665 ms 50484 KB Output is correct
100 Correct 553 ms 52464 KB Output is correct
101 Correct 495 ms 47768 KB Output is correct
102 Correct 348 ms 47820 KB Output is correct
103 Correct 338 ms 47764 KB Output is correct
104 Correct 239 ms 48220 KB Output is correct
105 Correct 606 ms 56656 KB Output is correct
106 Correct 717 ms 53620 KB Output is correct
107 Correct 519 ms 49268 KB Output is correct
108 Correct 610 ms 46316 KB Output is correct
109 Correct 422 ms 46944 KB Output is correct
110 Correct 425 ms 47352 KB Output is correct
111 Correct 1 ms 212 KB Output is correct
112 Correct 1 ms 212 KB Output is correct
113 Correct 0 ms 212 KB Output is correct
114 Correct 1 ms 212 KB Output is correct
115 Correct 1 ms 212 KB Output is correct
116 Correct 525 ms 47364 KB Output is correct
117 Correct 599 ms 45992 KB Output is correct
118 Correct 579 ms 55220 KB Output is correct
119 Correct 513 ms 47752 KB Output is correct
120 Correct 381 ms 47744 KB Output is correct
121 Correct 356 ms 47960 KB Output is correct
122 Correct 267 ms 48476 KB Output is correct
123 Correct 633 ms 55692 KB Output is correct
124 Correct 713 ms 51044 KB Output is correct
125 Correct 514 ms 48876 KB Output is correct
126 Correct 599 ms 46116 KB Output is correct
127 Correct 606 ms 45972 KB Output is correct
128 Correct 490 ms 46812 KB Output is correct
129 Correct 532 ms 47304 KB Output is correct