Submission #1004607

# Submission time Handle Problem Language Result Execution time Memory
1004607 2024-06-21T10:26:42 Z onbert Sprinkler (JOI22_sprinkler) C++17
100 / 100
986 ms 97212 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 2e5 + 5, m = 43;
int n, M;
vector<int> adj[maxn];
int d[maxn], fa[maxn];
bool vis[maxn];

void dfs(int u) {
    vis[u] = true;
    if (adj[u].size() == 0) return;
    for (int v:adj[u]) if (!vis[v]) {
        d[v] = d[u] + 1, fa[v] = u;
        dfs(v);
    }
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> M;
    for (int i=1;i<=n-1;i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    fa[1] = -1, d[1] = 0;
    dfs(1);
    int val[n+1][m];
    for (int i=1;i<=n;i++) for (int j=0;j<m;j++) val[i][j] = 1;
    for (int i=1;i<=n;i++) cin >> val[i][0];
    int q;
    cin >> q;
    while (q--) {
        int t;
        cin >> t;
        if (t==1) {
            int x, D, w;
            cin >> x >> D >> w;
            int v = x;
            // cout << "test" << endl;
            for (int dep = d[x]+D; dep>=d[x]-D && dep >= 0; dep--) {
                // cout << v << endl;
                if (fa[v]!=-1 && dep-d[v] + d[x]-d[v] + 2 <= D) v = fa[v];
                val[v][dep - d[v]] = val[v][dep - d[v]] * w % M;
                // cout << v << " " << dep - d[v] << endl;
            }
        } else if (t==2) {
            int x;
            cin >> x;
            int ans = 1;
            for (int v = x; v != -1 && d[x] - d[v] < m; v = fa[v]) {
                ans = ans * val[v][d[x] - d[v]] % M;
                // cout << v << " " << d[x] - d[v] << endl;
            }
            cout << ans << endl;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6232 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 4 ms 5468 KB Output is correct
5 Correct 3 ms 6492 KB Output is correct
6 Correct 4 ms 5432 KB Output is correct
7 Correct 3 ms 5468 KB Output is correct
8 Correct 3 ms 5468 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 3 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 3 ms 4956 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 ms 4956 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 2 ms 6252 KB Output is correct
21 Correct 2 ms 6236 KB Output is correct
22 Correct 3 ms 4956 KB Output is correct
23 Correct 3 ms 4956 KB Output is correct
24 Correct 2 ms 6236 KB Output is correct
25 Correct 3 ms 6236 KB Output is correct
26 Correct 3 ms 5160 KB Output is correct
27 Correct 3 ms 4956 KB Output is correct
28 Correct 4 ms 5152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 848 ms 94828 KB Output is correct
3 Correct 286 ms 95312 KB Output is correct
4 Correct 639 ms 93896 KB Output is correct
5 Correct 586 ms 95032 KB Output is correct
6 Correct 505 ms 94524 KB Output is correct
7 Correct 450 ms 95484 KB Output is correct
8 Correct 410 ms 95692 KB Output is correct
9 Correct 986 ms 93376 KB Output is correct
10 Correct 326 ms 94032 KB Output is correct
11 Correct 829 ms 94600 KB Output is correct
12 Correct 301 ms 95316 KB Output is correct
13 Correct 213 ms 95424 KB Output is correct
14 Correct 215 ms 95692 KB Output is correct
15 Correct 195 ms 94916 KB Output is correct
16 Correct 206 ms 95724 KB Output is correct
17 Correct 251 ms 96080 KB Output is correct
18 Correct 3 ms 6236 KB Output is correct
19 Correct 3 ms 6236 KB Output is correct
20 Correct 3 ms 4956 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 3 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 848 ms 94828 KB Output is correct
3 Correct 286 ms 95312 KB Output is correct
4 Correct 639 ms 93896 KB Output is correct
5 Correct 586 ms 95032 KB Output is correct
6 Correct 505 ms 94524 KB Output is correct
7 Correct 450 ms 95484 KB Output is correct
8 Correct 410 ms 95692 KB Output is correct
9 Correct 986 ms 93376 KB Output is correct
10 Correct 326 ms 94032 KB Output is correct
11 Correct 829 ms 94600 KB Output is correct
12 Correct 301 ms 95316 KB Output is correct
13 Correct 213 ms 95424 KB Output is correct
14 Correct 215 ms 95692 KB Output is correct
15 Correct 195 ms 94916 KB Output is correct
16 Correct 206 ms 95724 KB Output is correct
17 Correct 251 ms 96080 KB Output is correct
18 Correct 3 ms 6236 KB Output is correct
19 Correct 3 ms 6236 KB Output is correct
20 Correct 3 ms 4956 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 3 ms 4956 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 892 ms 94816 KB Output is correct
25 Correct 329 ms 95320 KB Output is correct
26 Correct 630 ms 93804 KB Output is correct
27 Correct 566 ms 95008 KB Output is correct
28 Correct 462 ms 95052 KB Output is correct
29 Correct 406 ms 85184 KB Output is correct
30 Correct 372 ms 93628 KB Output is correct
31 Correct 868 ms 92600 KB Output is correct
32 Correct 314 ms 91728 KB Output is correct
33 Correct 833 ms 89636 KB Output is correct
34 Correct 317 ms 83796 KB Output is correct
35 Correct 3 ms 6236 KB Output is correct
36 Correct 3 ms 5180 KB Output is correct
37 Correct 3 ms 4956 KB Output is correct
38 Correct 3 ms 5072 KB Output is correct
39 Correct 3 ms 5148 KB Output is correct
40 Correct 3 ms 4952 KB Output is correct
41 Correct 2 ms 4956 KB Output is correct
42 Correct 3 ms 4952 KB Output is correct
43 Correct 3 ms 4956 KB Output is correct
44 Correct 3 ms 5212 KB Output is correct
45 Correct 2 ms 4956 KB Output is correct
46 Correct 3 ms 4956 KB Output is correct
47 Correct 3 ms 4956 KB Output is correct
48 Correct 3 ms 4956 KB Output is correct
49 Correct 3 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6236 KB Output is correct
2 Correct 950 ms 82804 KB Output is correct
3 Correct 695 ms 91508 KB Output is correct
4 Correct 726 ms 90980 KB Output is correct
5 Correct 594 ms 92372 KB Output is correct
6 Correct 414 ms 92252 KB Output is correct
7 Correct 425 ms 92264 KB Output is correct
8 Correct 396 ms 92604 KB Output is correct
9 Correct 888 ms 90756 KB Output is correct
10 Correct 753 ms 91340 KB Output is correct
11 Correct 880 ms 91732 KB Output is correct
12 Correct 566 ms 92500 KB Output is correct
13 Correct 405 ms 93524 KB Output is correct
14 Correct 392 ms 94380 KB Output is correct
15 Correct 3 ms 6236 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 3 ms 4956 KB Output is correct
19 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 945 ms 89688 KB Output is correct
3 Correct 710 ms 89520 KB Output is correct
4 Correct 752 ms 92492 KB Output is correct
5 Correct 642 ms 93596 KB Output is correct
6 Correct 491 ms 93884 KB Output is correct
7 Correct 467 ms 93784 KB Output is correct
8 Correct 388 ms 93628 KB Output is correct
9 Correct 923 ms 93240 KB Output is correct
10 Correct 736 ms 91740 KB Output is correct
11 Correct 863 ms 94320 KB Output is correct
12 Correct 530 ms 92880 KB Output is correct
13 Correct 387 ms 93592 KB Output is correct
14 Correct 398 ms 94544 KB Output is correct
15 Correct 3 ms 6236 KB Output is correct
16 Correct 3 ms 5160 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 ms 5160 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6232 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 4 ms 5468 KB Output is correct
5 Correct 3 ms 6492 KB Output is correct
6 Correct 4 ms 5432 KB Output is correct
7 Correct 3 ms 5468 KB Output is correct
8 Correct 3 ms 5468 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 3 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 3 ms 4956 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 ms 4956 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 2 ms 6252 KB Output is correct
21 Correct 2 ms 6236 KB Output is correct
22 Correct 3 ms 4956 KB Output is correct
23 Correct 3 ms 4956 KB Output is correct
24 Correct 2 ms 6236 KB Output is correct
25 Correct 3 ms 6236 KB Output is correct
26 Correct 3 ms 5160 KB Output is correct
27 Correct 3 ms 4956 KB Output is correct
28 Correct 4 ms 5152 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Correct 848 ms 94828 KB Output is correct
31 Correct 286 ms 95312 KB Output is correct
32 Correct 639 ms 93896 KB Output is correct
33 Correct 586 ms 95032 KB Output is correct
34 Correct 505 ms 94524 KB Output is correct
35 Correct 450 ms 95484 KB Output is correct
36 Correct 410 ms 95692 KB Output is correct
37 Correct 986 ms 93376 KB Output is correct
38 Correct 326 ms 94032 KB Output is correct
39 Correct 829 ms 94600 KB Output is correct
40 Correct 301 ms 95316 KB Output is correct
41 Correct 213 ms 95424 KB Output is correct
42 Correct 215 ms 95692 KB Output is correct
43 Correct 195 ms 94916 KB Output is correct
44 Correct 206 ms 95724 KB Output is correct
45 Correct 251 ms 96080 KB Output is correct
46 Correct 3 ms 6236 KB Output is correct
47 Correct 3 ms 6236 KB Output is correct
48 Correct 3 ms 4956 KB Output is correct
49 Correct 3 ms 4956 KB Output is correct
50 Correct 3 ms 4956 KB Output is correct
51 Correct 2 ms 4956 KB Output is correct
52 Correct 892 ms 94816 KB Output is correct
53 Correct 329 ms 95320 KB Output is correct
54 Correct 630 ms 93804 KB Output is correct
55 Correct 566 ms 95008 KB Output is correct
56 Correct 462 ms 95052 KB Output is correct
57 Correct 406 ms 85184 KB Output is correct
58 Correct 372 ms 93628 KB Output is correct
59 Correct 868 ms 92600 KB Output is correct
60 Correct 314 ms 91728 KB Output is correct
61 Correct 833 ms 89636 KB Output is correct
62 Correct 317 ms 83796 KB Output is correct
63 Correct 3 ms 6236 KB Output is correct
64 Correct 3 ms 5180 KB Output is correct
65 Correct 3 ms 4956 KB Output is correct
66 Correct 3 ms 5072 KB Output is correct
67 Correct 3 ms 5148 KB Output is correct
68 Correct 3 ms 4952 KB Output is correct
69 Correct 2 ms 4956 KB Output is correct
70 Correct 3 ms 4952 KB Output is correct
71 Correct 3 ms 4956 KB Output is correct
72 Correct 3 ms 5212 KB Output is correct
73 Correct 2 ms 4956 KB Output is correct
74 Correct 3 ms 4956 KB Output is correct
75 Correct 3 ms 4956 KB Output is correct
76 Correct 3 ms 4956 KB Output is correct
77 Correct 3 ms 4956 KB Output is correct
78 Correct 2 ms 6236 KB Output is correct
79 Correct 950 ms 82804 KB Output is correct
80 Correct 695 ms 91508 KB Output is correct
81 Correct 726 ms 90980 KB Output is correct
82 Correct 594 ms 92372 KB Output is correct
83 Correct 414 ms 92252 KB Output is correct
84 Correct 425 ms 92264 KB Output is correct
85 Correct 396 ms 92604 KB Output is correct
86 Correct 888 ms 90756 KB Output is correct
87 Correct 753 ms 91340 KB Output is correct
88 Correct 880 ms 91732 KB Output is correct
89 Correct 566 ms 92500 KB Output is correct
90 Correct 405 ms 93524 KB Output is correct
91 Correct 392 ms 94380 KB Output is correct
92 Correct 3 ms 6236 KB Output is correct
93 Correct 2 ms 4956 KB Output is correct
94 Correct 2 ms 4956 KB Output is correct
95 Correct 3 ms 4956 KB Output is correct
96 Correct 2 ms 4956 KB Output is correct
97 Correct 2 ms 4956 KB Output is correct
98 Correct 945 ms 89688 KB Output is correct
99 Correct 710 ms 89520 KB Output is correct
100 Correct 752 ms 92492 KB Output is correct
101 Correct 642 ms 93596 KB Output is correct
102 Correct 491 ms 93884 KB Output is correct
103 Correct 467 ms 93784 KB Output is correct
104 Correct 388 ms 93628 KB Output is correct
105 Correct 923 ms 93240 KB Output is correct
106 Correct 736 ms 91740 KB Output is correct
107 Correct 863 ms 94320 KB Output is correct
108 Correct 530 ms 92880 KB Output is correct
109 Correct 387 ms 93592 KB Output is correct
110 Correct 398 ms 94544 KB Output is correct
111 Correct 3 ms 6236 KB Output is correct
112 Correct 3 ms 5160 KB Output is correct
113 Correct 3 ms 4956 KB Output is correct
114 Correct 3 ms 5160 KB Output is correct
115 Correct 3 ms 4956 KB Output is correct
116 Correct 839 ms 92800 KB Output is correct
117 Correct 525 ms 95348 KB Output is correct
118 Correct 698 ms 94160 KB Output is correct
119 Correct 661 ms 94936 KB Output is correct
120 Correct 507 ms 94800 KB Output is correct
121 Correct 451 ms 95660 KB Output is correct
122 Correct 386 ms 95532 KB Output is correct
123 Correct 921 ms 93780 KB Output is correct
124 Correct 764 ms 94000 KB Output is correct
125 Correct 856 ms 93968 KB Output is correct
126 Correct 612 ms 95392 KB Output is correct
127 Correct 560 ms 95624 KB Output is correct
128 Correct 387 ms 96344 KB Output is correct
129 Correct 424 ms 97212 KB Output is correct