Submission #1115667

# Submission time Handle Problem Language Result Execution time Memory
1115667 2024-11-20T18:30:11 Z Pekiban Sprinkler (JOI22_sprinkler) C++17
100 / 100
580 ms 101540 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define pb push_back

const int N = 2e5+5, D = 45;
ll dp[N + D][D], p[N];
vector<int> g[N];
void dfs(int s, int e = -1) {
    for (auto u : g[s]) {
        if (u == e) continue;
        p[u] = s;
        dfs(u, s);
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, L;
    cin >> n >> L;
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].pb(v); g[v].pb(u);
    }
    p[1] = n+1;
    for (int i = n+1; i < n + D; ++i)  p[i] = i+1;
    dfs(1);
    for (int i = 1; i <= n; ++i)    cin >> dp[i][0];
    for (int i = 1; i <= n+D; ++i) {
        for (int j = 1; j < D; ++j) dp[i][j] = 1;
    }
    int q;
    cin >> q;
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int u, d, w;
            cin >> u >> d >> w;
            while (u < n + D && d > -1) {
                dp[u][d] = (dp[u][d] * w) % L;
                if (d)  dp[u][d-1] = (dp[u][d-1] * w) % L;
                --d; u = p[u];
            }
        }
        if (t == 2) {
            ll ans = 1, u;
            cin >> u;
            for (int i = 0; i < D && u; ++i) {
                ans *= dp[u][i];
                ans %= L;
                u = p[u];
            }
            cout << ans << '\n';
        }
        
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6736 KB Output is correct
2 Correct 2 ms 6736 KB Output is correct
3 Correct 2 ms 6904 KB Output is correct
4 Correct 3 ms 8784 KB Output is correct
5 Correct 3 ms 8784 KB Output is correct
6 Correct 2 ms 8784 KB Output is correct
7 Correct 2 ms 8784 KB Output is correct
8 Correct 3 ms 8784 KB Output is correct
9 Correct 2 ms 6736 KB Output is correct
10 Correct 2 ms 6736 KB Output is correct
11 Correct 2 ms 6736 KB Output is correct
12 Correct 2 ms 6736 KB Output is correct
13 Correct 2 ms 6736 KB Output is correct
14 Correct 2 ms 6736 KB Output is correct
15 Correct 2 ms 6736 KB Output is correct
16 Correct 2 ms 6904 KB Output is correct
17 Correct 2 ms 6736 KB Output is correct
18 Correct 2 ms 6736 KB Output is correct
19 Correct 2 ms 6736 KB Output is correct
20 Correct 2 ms 6736 KB Output is correct
21 Correct 2 ms 6736 KB Output is correct
22 Correct 3 ms 6736 KB Output is correct
23 Correct 2 ms 6736 KB Output is correct
24 Correct 3 ms 6736 KB Output is correct
25 Correct 2 ms 6736 KB Output is correct
26 Correct 2 ms 6736 KB Output is correct
27 Correct 2 ms 6904 KB Output is correct
28 Correct 2 ms 6736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6736 KB Output is correct
2 Correct 446 ms 95164 KB Output is correct
3 Correct 231 ms 95808 KB Output is correct
4 Correct 384 ms 99400 KB Output is correct
5 Correct 351 ms 95384 KB Output is correct
6 Correct 260 ms 95048 KB Output is correct
7 Correct 257 ms 95776 KB Output is correct
8 Correct 214 ms 96248 KB Output is correct
9 Correct 470 ms 101456 KB Output is correct
10 Correct 250 ms 101448 KB Output is correct
11 Correct 409 ms 95304 KB Output is correct
12 Correct 248 ms 95816 KB Output is correct
13 Correct 177 ms 96008 KB Output is correct
14 Correct 167 ms 96444 KB Output is correct
15 Correct 179 ms 95816 KB Output is correct
16 Correct 184 ms 96308 KB Output is correct
17 Correct 196 ms 96840 KB Output is correct
18 Correct 2 ms 6736 KB Output is correct
19 Correct 2 ms 6736 KB Output is correct
20 Correct 2 ms 6736 KB Output is correct
21 Correct 2 ms 6736 KB Output is correct
22 Correct 2 ms 6820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6736 KB Output is correct
2 Correct 446 ms 95164 KB Output is correct
3 Correct 231 ms 95808 KB Output is correct
4 Correct 384 ms 99400 KB Output is correct
5 Correct 351 ms 95384 KB Output is correct
6 Correct 260 ms 95048 KB Output is correct
7 Correct 257 ms 95776 KB Output is correct
8 Correct 214 ms 96248 KB Output is correct
9 Correct 470 ms 101456 KB Output is correct
10 Correct 250 ms 101448 KB Output is correct
11 Correct 409 ms 95304 KB Output is correct
12 Correct 248 ms 95816 KB Output is correct
13 Correct 177 ms 96008 KB Output is correct
14 Correct 167 ms 96444 KB Output is correct
15 Correct 179 ms 95816 KB Output is correct
16 Correct 184 ms 96308 KB Output is correct
17 Correct 196 ms 96840 KB Output is correct
18 Correct 2 ms 6736 KB Output is correct
19 Correct 2 ms 6736 KB Output is correct
20 Correct 2 ms 6736 KB Output is correct
21 Correct 2 ms 6736 KB Output is correct
22 Correct 2 ms 6820 KB Output is correct
23 Correct 3 ms 6736 KB Output is correct
24 Correct 394 ms 95152 KB Output is correct
25 Correct 243 ms 95816 KB Output is correct
26 Correct 357 ms 101444 KB Output is correct
27 Correct 338 ms 95304 KB Output is correct
28 Correct 259 ms 95560 KB Output is correct
29 Correct 223 ms 95304 KB Output is correct
30 Correct 229 ms 96288 KB Output is correct
31 Correct 496 ms 99480 KB Output is correct
32 Correct 281 ms 101448 KB Output is correct
33 Correct 434 ms 95304 KB Output is correct
34 Correct 248 ms 95816 KB Output is correct
35 Correct 3 ms 6736 KB Output is correct
36 Correct 2 ms 6736 KB Output is correct
37 Correct 3 ms 6736 KB Output is correct
38 Correct 2 ms 6736 KB Output is correct
39 Correct 3 ms 6900 KB Output is correct
40 Correct 2 ms 6804 KB Output is correct
41 Correct 2 ms 6900 KB Output is correct
42 Correct 3 ms 6736 KB Output is correct
43 Correct 2 ms 6736 KB Output is correct
44 Correct 2 ms 6736 KB Output is correct
45 Correct 3 ms 6736 KB Output is correct
46 Correct 2 ms 6736 KB Output is correct
47 Correct 2 ms 6736 KB Output is correct
48 Correct 2 ms 6736 KB Output is correct
49 Correct 2 ms 6812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6736 KB Output is correct
2 Correct 476 ms 98464 KB Output is correct
3 Correct 481 ms 97608 KB Output is correct
4 Correct 476 ms 97352 KB Output is correct
5 Correct 387 ms 92388 KB Output is correct
6 Correct 276 ms 92752 KB Output is correct
7 Correct 311 ms 92852 KB Output is correct
8 Correct 236 ms 93376 KB Output is correct
9 Correct 515 ms 96584 KB Output is correct
10 Correct 514 ms 98464 KB Output is correct
11 Correct 408 ms 92176 KB Output is correct
12 Correct 377 ms 92996 KB Output is correct
13 Correct 245 ms 94024 KB Output is correct
14 Correct 254 ms 94332 KB Output is correct
15 Correct 2 ms 6904 KB Output is correct
16 Correct 2 ms 6736 KB Output is correct
17 Correct 2 ms 6736 KB Output is correct
18 Correct 2 ms 6736 KB Output is correct
19 Correct 3 ms 7004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6736 KB Output is correct
2 Correct 496 ms 98964 KB Output is correct
3 Correct 571 ms 96492 KB Output is correct
4 Correct 485 ms 97612 KB Output is correct
5 Correct 363 ms 94024 KB Output is correct
6 Correct 306 ms 94460 KB Output is correct
7 Correct 272 ms 94016 KB Output is correct
8 Correct 352 ms 94344 KB Output is correct
9 Correct 507 ms 100680 KB Output is correct
10 Correct 536 ms 99444 KB Output is correct
11 Correct 443 ms 94792 KB Output is correct
12 Correct 446 ms 93332 KB Output is correct
13 Correct 244 ms 94028 KB Output is correct
14 Correct 243 ms 94664 KB Output is correct
15 Correct 2 ms 6736 KB Output is correct
16 Correct 2 ms 6812 KB Output is correct
17 Correct 2 ms 6736 KB Output is correct
18 Correct 2 ms 6576 KB Output is correct
19 Correct 2 ms 6904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6736 KB Output is correct
2 Correct 2 ms 6736 KB Output is correct
3 Correct 2 ms 6904 KB Output is correct
4 Correct 3 ms 8784 KB Output is correct
5 Correct 3 ms 8784 KB Output is correct
6 Correct 2 ms 8784 KB Output is correct
7 Correct 2 ms 8784 KB Output is correct
8 Correct 3 ms 8784 KB Output is correct
9 Correct 2 ms 6736 KB Output is correct
10 Correct 2 ms 6736 KB Output is correct
11 Correct 2 ms 6736 KB Output is correct
12 Correct 2 ms 6736 KB Output is correct
13 Correct 2 ms 6736 KB Output is correct
14 Correct 2 ms 6736 KB Output is correct
15 Correct 2 ms 6736 KB Output is correct
16 Correct 2 ms 6904 KB Output is correct
17 Correct 2 ms 6736 KB Output is correct
18 Correct 2 ms 6736 KB Output is correct
19 Correct 2 ms 6736 KB Output is correct
20 Correct 2 ms 6736 KB Output is correct
21 Correct 2 ms 6736 KB Output is correct
22 Correct 3 ms 6736 KB Output is correct
23 Correct 2 ms 6736 KB Output is correct
24 Correct 3 ms 6736 KB Output is correct
25 Correct 2 ms 6736 KB Output is correct
26 Correct 2 ms 6736 KB Output is correct
27 Correct 2 ms 6904 KB Output is correct
28 Correct 2 ms 6736 KB Output is correct
29 Correct 3 ms 6736 KB Output is correct
30 Correct 446 ms 95164 KB Output is correct
31 Correct 231 ms 95808 KB Output is correct
32 Correct 384 ms 99400 KB Output is correct
33 Correct 351 ms 95384 KB Output is correct
34 Correct 260 ms 95048 KB Output is correct
35 Correct 257 ms 95776 KB Output is correct
36 Correct 214 ms 96248 KB Output is correct
37 Correct 470 ms 101456 KB Output is correct
38 Correct 250 ms 101448 KB Output is correct
39 Correct 409 ms 95304 KB Output is correct
40 Correct 248 ms 95816 KB Output is correct
41 Correct 177 ms 96008 KB Output is correct
42 Correct 167 ms 96444 KB Output is correct
43 Correct 179 ms 95816 KB Output is correct
44 Correct 184 ms 96308 KB Output is correct
45 Correct 196 ms 96840 KB Output is correct
46 Correct 2 ms 6736 KB Output is correct
47 Correct 2 ms 6736 KB Output is correct
48 Correct 2 ms 6736 KB Output is correct
49 Correct 2 ms 6736 KB Output is correct
50 Correct 2 ms 6820 KB Output is correct
51 Correct 3 ms 6736 KB Output is correct
52 Correct 394 ms 95152 KB Output is correct
53 Correct 243 ms 95816 KB Output is correct
54 Correct 357 ms 101444 KB Output is correct
55 Correct 338 ms 95304 KB Output is correct
56 Correct 259 ms 95560 KB Output is correct
57 Correct 223 ms 95304 KB Output is correct
58 Correct 229 ms 96288 KB Output is correct
59 Correct 496 ms 99480 KB Output is correct
60 Correct 281 ms 101448 KB Output is correct
61 Correct 434 ms 95304 KB Output is correct
62 Correct 248 ms 95816 KB Output is correct
63 Correct 3 ms 6736 KB Output is correct
64 Correct 2 ms 6736 KB Output is correct
65 Correct 3 ms 6736 KB Output is correct
66 Correct 2 ms 6736 KB Output is correct
67 Correct 3 ms 6900 KB Output is correct
68 Correct 2 ms 6804 KB Output is correct
69 Correct 2 ms 6900 KB Output is correct
70 Correct 3 ms 6736 KB Output is correct
71 Correct 2 ms 6736 KB Output is correct
72 Correct 2 ms 6736 KB Output is correct
73 Correct 3 ms 6736 KB Output is correct
74 Correct 2 ms 6736 KB Output is correct
75 Correct 2 ms 6736 KB Output is correct
76 Correct 2 ms 6736 KB Output is correct
77 Correct 2 ms 6812 KB Output is correct
78 Correct 2 ms 6736 KB Output is correct
79 Correct 476 ms 98464 KB Output is correct
80 Correct 481 ms 97608 KB Output is correct
81 Correct 476 ms 97352 KB Output is correct
82 Correct 387 ms 92388 KB Output is correct
83 Correct 276 ms 92752 KB Output is correct
84 Correct 311 ms 92852 KB Output is correct
85 Correct 236 ms 93376 KB Output is correct
86 Correct 515 ms 96584 KB Output is correct
87 Correct 514 ms 98464 KB Output is correct
88 Correct 408 ms 92176 KB Output is correct
89 Correct 377 ms 92996 KB Output is correct
90 Correct 245 ms 94024 KB Output is correct
91 Correct 254 ms 94332 KB Output is correct
92 Correct 2 ms 6904 KB Output is correct
93 Correct 2 ms 6736 KB Output is correct
94 Correct 2 ms 6736 KB Output is correct
95 Correct 2 ms 6736 KB Output is correct
96 Correct 3 ms 7004 KB Output is correct
97 Correct 2 ms 6736 KB Output is correct
98 Correct 496 ms 98964 KB Output is correct
99 Correct 571 ms 96492 KB Output is correct
100 Correct 485 ms 97612 KB Output is correct
101 Correct 363 ms 94024 KB Output is correct
102 Correct 306 ms 94460 KB Output is correct
103 Correct 272 ms 94016 KB Output is correct
104 Correct 352 ms 94344 KB Output is correct
105 Correct 507 ms 100680 KB Output is correct
106 Correct 536 ms 99444 KB Output is correct
107 Correct 443 ms 94792 KB Output is correct
108 Correct 446 ms 93332 KB Output is correct
109 Correct 244 ms 94028 KB Output is correct
110 Correct 243 ms 94664 KB Output is correct
111 Correct 2 ms 6736 KB Output is correct
112 Correct 2 ms 6812 KB Output is correct
113 Correct 2 ms 6736 KB Output is correct
114 Correct 2 ms 6576 KB Output is correct
115 Correct 2 ms 6904 KB Output is correct
116 Correct 394 ms 93172 KB Output is correct
117 Correct 398 ms 95780 KB Output is correct
118 Correct 459 ms 101540 KB Output is correct
119 Correct 387 ms 95508 KB Output is correct
120 Correct 299 ms 95488 KB Output is correct
121 Correct 270 ms 95820 KB Output is correct
122 Correct 243 ms 96188 KB Output is correct
123 Correct 490 ms 100172 KB Output is correct
124 Correct 580 ms 99400 KB Output is correct
125 Correct 484 ms 94284 KB Output is correct
126 Correct 444 ms 95604 KB Output is correct
127 Correct 453 ms 96080 KB Output is correct
128 Correct 293 ms 96840 KB Output is correct
129 Correct 321 ms 97420 KB Output is correct