Submission #1015946

# Submission time Handle Problem Language Result Execution time Memory
1015946 2024-07-07T06:28:52 Z TAhmed33 Sprinkler (JOI22_sprinkler) C++
100 / 100
492 ms 69460 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int B = 40;
const int MAXN = 2e5 + 40 + 25;
int n, l, p[MAXN];
vector <int> adj[MAXN];
int dp[MAXN][B + 1], dep[MAXN];
int mul (int x, int y) {
    return (x * 1ll * y) % l;
}
int h[MAXN];
void dfs (int pos, int par) {
    p[pos] = par;
    for (auto j : adj[pos]) {
        if (j != par) {
            dep[j] = 1 + dep[pos];
            dfs(j, pos);
        }
    }
}
void solve () {
    cin >> n >> l;
    for (int i = 1; i < n; i++) {
        int x, y; cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dfs(1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    p[1] = n + 1;
    for (int i = n + 2; i <= n + 40; i++) {
        p[i - 1] = i;
    }
    for (int i = 1; i <= n + 40; i++) {
        for (int j = 0; j <= B; j++) {
            dp[i][j] = 1;
        }
    }
    int q; cin >> q;
    while (q--) {
        int t; cin >> t;
        if (t == 1) {
            int x, d, w; cin >> x >> d >> w;
            for (int i = d; i >= 0; i--) {
                dp[x][i] = mul(dp[x][i], w);
                if (i) {
                    dp[x][i - 1] = mul(dp[x][i - 1], w);
                }
                x = p[x];
            }
        } else {
            int x; cin >> x;
            int ret = h[x];
            for (int i = 0; i <= B; i++) {
                ret = mul(ret, dp[x][i]);
                x = p[x];
            }
            cout << ret << '\n';
        }
    }
}       
signed main () {
    ios::sync_with_stdio(0); cin.tie(0);
    int tc = 1; //cin >> tc;
    while (tc--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 2 ms 5160 KB Output is correct
4 Correct 3 ms 5208 KB Output is correct
5 Correct 3 ms 5212 KB Output is correct
6 Correct 3 ms 5212 KB Output is correct
7 Correct 2 ms 5212 KB Output is correct
8 Correct 3 ms 5180 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 5212 KB Output is correct
12 Correct 2 ms 5164 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 2 ms 4956 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 5168 KB Output is correct
24 Correct 2 ms 5032 KB Output is correct
25 Correct 2 ms 5168 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 3 ms 4956 KB Output is correct
28 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 387 ms 57644 KB Output is correct
3 Correct 205 ms 58196 KB Output is correct
4 Correct 323 ms 65640 KB Output is correct
5 Correct 276 ms 57936 KB Output is correct
6 Correct 217 ms 57660 KB Output is correct
7 Correct 194 ms 58192 KB Output is correct
8 Correct 185 ms 58568 KB Output is correct
9 Correct 415 ms 69460 KB Output is correct
10 Correct 228 ms 69140 KB Output is correct
11 Correct 321 ms 57684 KB Output is correct
12 Correct 211 ms 58196 KB Output is correct
13 Correct 155 ms 58488 KB Output is correct
14 Correct 155 ms 58868 KB Output is correct
15 Correct 170 ms 58192 KB Output is correct
16 Correct 181 ms 58628 KB Output is correct
17 Correct 170 ms 59228 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 5980 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 2 ms 5980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 387 ms 57644 KB Output is correct
3 Correct 205 ms 58196 KB Output is correct
4 Correct 323 ms 65640 KB Output is correct
5 Correct 276 ms 57936 KB Output is correct
6 Correct 217 ms 57660 KB Output is correct
7 Correct 194 ms 58192 KB Output is correct
8 Correct 185 ms 58568 KB Output is correct
9 Correct 415 ms 69460 KB Output is correct
10 Correct 228 ms 69140 KB Output is correct
11 Correct 321 ms 57684 KB Output is correct
12 Correct 211 ms 58196 KB Output is correct
13 Correct 155 ms 58488 KB Output is correct
14 Correct 155 ms 58868 KB Output is correct
15 Correct 170 ms 58192 KB Output is correct
16 Correct 181 ms 58628 KB Output is correct
17 Correct 170 ms 59228 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 5980 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 2 ms 5980 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 369 ms 57588 KB Output is correct
25 Correct 226 ms 58192 KB Output is correct
26 Correct 312 ms 69444 KB Output is correct
27 Correct 282 ms 57788 KB Output is correct
28 Correct 223 ms 57940 KB Output is correct
29 Correct 225 ms 47956 KB Output is correct
30 Correct 202 ms 56752 KB Output is correct
31 Correct 437 ms 65028 KB Output is correct
32 Correct 242 ms 66896 KB Output is correct
33 Correct 359 ms 52388 KB Output is correct
34 Correct 229 ms 46720 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 6604 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 2 ms 4956 KB Output is correct
41 Correct 2 ms 4952 KB Output is correct
42 Correct 3 ms 5180 KB Output is correct
43 Correct 2 ms 5136 KB Output is correct
44 Correct 1 ms 6492 KB Output is correct
45 Correct 3 ms 4956 KB Output is correct
46 Correct 2 ms 4956 KB Output is correct
47 Correct 3 ms 5164 KB Output is correct
48 Correct 3 ms 4956 KB Output is correct
49 Correct 4 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 425 ms 58872 KB Output is correct
3 Correct 461 ms 64420 KB Output is correct
4 Correct 385 ms 64428 KB Output is correct
5 Correct 317 ms 54864 KB Output is correct
6 Correct 224 ms 55180 KB Output is correct
7 Correct 218 ms 55124 KB Output is correct
8 Correct 193 ms 55632 KB Output is correct
9 Correct 436 ms 63060 KB Output is correct
10 Correct 447 ms 66032 KB Output is correct
11 Correct 342 ms 54492 KB Output is correct
12 Correct 352 ms 55376 KB Output is correct
13 Correct 288 ms 56404 KB Output is correct
14 Correct 289 ms 57172 KB Output is correct
15 Correct 3 ms 5724 KB Output is correct
16 Correct 3 ms 5724 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 413 ms 61356 KB Output is correct
3 Correct 486 ms 59524 KB Output is correct
4 Correct 385 ms 63548 KB Output is correct
5 Correct 359 ms 56660 KB Output is correct
6 Correct 250 ms 56580 KB Output is correct
7 Correct 280 ms 56388 KB Output is correct
8 Correct 252 ms 56660 KB Output is correct
9 Correct 440 ms 68436 KB Output is correct
10 Correct 474 ms 67052 KB Output is correct
11 Correct 394 ms 57168 KB Output is correct
12 Correct 397 ms 55632 KB Output is correct
13 Correct 296 ms 56392 KB Output is correct
14 Correct 263 ms 56976 KB Output is correct
15 Correct 2 ms 4952 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 3 ms 5192 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 2 ms 5160 KB Output is correct
4 Correct 3 ms 5208 KB Output is correct
5 Correct 3 ms 5212 KB Output is correct
6 Correct 3 ms 5212 KB Output is correct
7 Correct 2 ms 5212 KB Output is correct
8 Correct 3 ms 5180 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 5212 KB Output is correct
12 Correct 2 ms 5164 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 2 ms 4956 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 5168 KB Output is correct
24 Correct 2 ms 5032 KB Output is correct
25 Correct 2 ms 5168 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 3 ms 4956 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Correct 387 ms 57644 KB Output is correct
31 Correct 205 ms 58196 KB Output is correct
32 Correct 323 ms 65640 KB Output is correct
33 Correct 276 ms 57936 KB Output is correct
34 Correct 217 ms 57660 KB Output is correct
35 Correct 194 ms 58192 KB Output is correct
36 Correct 185 ms 58568 KB Output is correct
37 Correct 415 ms 69460 KB Output is correct
38 Correct 228 ms 69140 KB Output is correct
39 Correct 321 ms 57684 KB Output is correct
40 Correct 211 ms 58196 KB Output is correct
41 Correct 155 ms 58488 KB Output is correct
42 Correct 155 ms 58868 KB Output is correct
43 Correct 170 ms 58192 KB Output is correct
44 Correct 181 ms 58628 KB Output is correct
45 Correct 170 ms 59228 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 5980 KB Output is correct
49 Correct 1 ms 6492 KB Output is correct
50 Correct 2 ms 5980 KB Output is correct
51 Correct 2 ms 4956 KB Output is correct
52 Correct 369 ms 57588 KB Output is correct
53 Correct 226 ms 58192 KB Output is correct
54 Correct 312 ms 69444 KB Output is correct
55 Correct 282 ms 57788 KB Output is correct
56 Correct 223 ms 57940 KB Output is correct
57 Correct 225 ms 47956 KB Output is correct
58 Correct 202 ms 56752 KB Output is correct
59 Correct 437 ms 65028 KB Output is correct
60 Correct 242 ms 66896 KB Output is correct
61 Correct 359 ms 52388 KB Output is correct
62 Correct 229 ms 46720 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 6604 KB Output is correct
67 Correct 1 ms 6492 KB Output is correct
68 Correct 2 ms 4956 KB Output is correct
69 Correct 2 ms 4952 KB Output is correct
70 Correct 3 ms 5180 KB Output is correct
71 Correct 2 ms 5136 KB Output is correct
72 Correct 1 ms 6492 KB Output is correct
73 Correct 3 ms 4956 KB Output is correct
74 Correct 2 ms 4956 KB Output is correct
75 Correct 3 ms 5164 KB Output is correct
76 Correct 3 ms 4956 KB Output is correct
77 Correct 4 ms 4956 KB Output is correct
78 Correct 2 ms 4956 KB Output is correct
79 Correct 425 ms 58872 KB Output is correct
80 Correct 461 ms 64420 KB Output is correct
81 Correct 385 ms 64428 KB Output is correct
82 Correct 317 ms 54864 KB Output is correct
83 Correct 224 ms 55180 KB Output is correct
84 Correct 218 ms 55124 KB Output is correct
85 Correct 193 ms 55632 KB Output is correct
86 Correct 436 ms 63060 KB Output is correct
87 Correct 447 ms 66032 KB Output is correct
88 Correct 342 ms 54492 KB Output is correct
89 Correct 352 ms 55376 KB Output is correct
90 Correct 288 ms 56404 KB Output is correct
91 Correct 289 ms 57172 KB Output is correct
92 Correct 3 ms 5724 KB Output is correct
93 Correct 3 ms 5724 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 413 ms 61356 KB Output is correct
99 Correct 486 ms 59524 KB Output is correct
100 Correct 385 ms 63548 KB Output is correct
101 Correct 359 ms 56660 KB Output is correct
102 Correct 250 ms 56580 KB Output is correct
103 Correct 280 ms 56388 KB Output is correct
104 Correct 252 ms 56660 KB Output is correct
105 Correct 440 ms 68436 KB Output is correct
106 Correct 474 ms 67052 KB Output is correct
107 Correct 394 ms 57168 KB Output is correct
108 Correct 397 ms 55632 KB Output is correct
109 Correct 296 ms 56392 KB Output is correct
110 Correct 263 ms 56976 KB Output is correct
111 Correct 2 ms 4952 KB Output is correct
112 Correct 2 ms 4952 KB Output is correct
113 Correct 3 ms 5192 KB Output is correct
114 Correct 2 ms 4956 KB Output is correct
115 Correct 2 ms 4956 KB Output is correct
116 Correct 395 ms 55636 KB Output is correct
117 Correct 429 ms 58304 KB Output is correct
118 Correct 430 ms 69204 KB Output is correct
119 Correct 367 ms 57984 KB Output is correct
120 Correct 271 ms 57636 KB Output is correct
121 Correct 295 ms 58320 KB Output is correct
122 Correct 249 ms 58564 KB Output is correct
123 Correct 469 ms 67152 KB Output is correct
124 Correct 492 ms 65200 KB Output is correct
125 Correct 401 ms 57120 KB Output is correct
126 Correct 429 ms 58032 KB Output is correct
127 Correct 417 ms 58708 KB Output is correct
128 Correct 275 ms 59220 KB Output is correct
129 Correct 285 ms 59740 KB Output is correct