Submission #1117765

# Submission time Handle Problem Language Result Execution time Memory
1117765 2024-11-24T08:12:49 Z Zero_OP Sprinkler (JOI22_sprinkler) C++14
100 / 100
1022 ms 71856 KB
#include <bits/stdc++.h>

using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

#ifdef LOCAL
    freopen("task.inp", "r", stdin);
    freopen("task.out", "w", stdout);
#endif // LOCAL

    int N, L;
    cin >> N >> L;
    vector<vector<int>> adj(N + 41);
    for(int i = 1; i < N; ++i){
        int u, v;
        cin >> u >> v;
        --u, --v;
        u += 41;
        v += 41;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
    }

    for(int i = 1; i <= 41; ++i){
         adj[i - 1].emplace_back(i);
    }

    vector<int> H(N + 41), par(N + 41, -1);
    for(int i = 0; i < N; ++i) cin >> H[i + 41];
    vector<vector<int>> f(41, vector<int>(N + 41, 1));

    function<void(int, int)> dfs = [&](int u, int p){
        for(int v : adj[u]) if(v != p){
            par[v] = u;
//            cout << v << " : " << u << '\n';
            dfs(v, u);
        }
    };

    dfs(0, -1);

    int Q;
    cin >> Q;
    while(Q--){
        int type;
        cin >> type;
        if(type == 1){
            int x, d, w;
            cin >> x >> d >> w;
            --x;
            x += 41;
            for(int i = d; i >= 0; --i){
                assert(x != -1);
                f[i][x] = 1LL * f[i][x] * w % L;
//                cout << "update : " << i << ' ' << x - 41 << " : " << f[i][x] << '\n';
                if(i > 0) f[i - 1][x] = 1ll * f[i - 1][x] * w % L;
                x = par[x];
            }
//            cout << '\n';
        } else{
            int x; cin >> x;
            --x;
            x += 41;
            int res = H[x];
            for(int i = 0; i <= 40; ++i){
                assert(x != -1);
//                cout << i << " - " << x - 41 << " -> " << f[i][x] << '\n';
                res = 1LL * res * f[i][x] % L;
                x = par[x];
            }

            cout << res << '\n';
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 768 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 1 ms 556 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 2 ms 336 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 506 ms 57120 KB Output is correct
3 Correct 240 ms 57552 KB Output is correct
4 Correct 389 ms 67144 KB Output is correct
5 Correct 345 ms 57252 KB Output is correct
6 Correct 266 ms 56820 KB Output is correct
7 Correct 256 ms 57488 KB Output is correct
8 Correct 208 ms 57904 KB Output is correct
9 Correct 507 ms 71856 KB Output is correct
10 Correct 288 ms 71224 KB Output is correct
11 Correct 469 ms 56936 KB Output is correct
12 Correct 228 ms 57408 KB Output is correct
13 Correct 180 ms 57652 KB Output is correct
14 Correct 182 ms 58284 KB Output is correct
15 Correct 198 ms 57540 KB Output is correct
16 Correct 190 ms 58008 KB Output is correct
17 Correct 194 ms 58680 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 2 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 506 ms 57120 KB Output is correct
3 Correct 240 ms 57552 KB Output is correct
4 Correct 389 ms 67144 KB Output is correct
5 Correct 345 ms 57252 KB Output is correct
6 Correct 266 ms 56820 KB Output is correct
7 Correct 256 ms 57488 KB Output is correct
8 Correct 208 ms 57904 KB Output is correct
9 Correct 507 ms 71856 KB Output is correct
10 Correct 288 ms 71224 KB Output is correct
11 Correct 469 ms 56936 KB Output is correct
12 Correct 228 ms 57408 KB Output is correct
13 Correct 180 ms 57652 KB Output is correct
14 Correct 182 ms 58284 KB Output is correct
15 Correct 198 ms 57540 KB Output is correct
16 Correct 190 ms 58008 KB Output is correct
17 Correct 194 ms 58680 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 2 ms 508 KB Output is correct
23 Correct 1 ms 504 KB Output is correct
24 Correct 499 ms 56920 KB Output is correct
25 Correct 274 ms 57408 KB Output is correct
26 Correct 460 ms 71668 KB Output is correct
27 Correct 402 ms 57148 KB Output is correct
28 Correct 245 ms 57400 KB Output is correct
29 Correct 248 ms 57108 KB Output is correct
30 Correct 206 ms 58028 KB Output is correct
31 Correct 502 ms 67384 KB Output is correct
32 Correct 287 ms 71268 KB Output is correct
33 Correct 448 ms 57152 KB Output is correct
34 Correct 261 ms 57400 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 560 KB Output is correct
40 Correct 1 ms 592 KB Output is correct
41 Correct 1 ms 464 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 1 ms 504 KB Output is correct
46 Correct 2 ms 336 KB Output is correct
47 Correct 1 ms 336 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 616 ms 68924 KB Output is correct
3 Correct 832 ms 65896 KB Output is correct
4 Correct 521 ms 66104 KB Output is correct
5 Correct 484 ms 54228 KB Output is correct
6 Correct 371 ms 54380 KB Output is correct
7 Correct 335 ms 54440 KB Output is correct
8 Correct 268 ms 54980 KB Output is correct
9 Correct 638 ms 64428 KB Output is correct
10 Correct 849 ms 68152 KB Output is correct
11 Correct 577 ms 53816 KB Output is correct
12 Correct 729 ms 54840 KB Output is correct
13 Correct 570 ms 55608 KB Output is correct
14 Correct 527 ms 56168 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 603 ms 66580 KB Output is correct
3 Correct 908 ms 62820 KB Output is correct
4 Correct 575 ms 64848 KB Output is correct
5 Correct 498 ms 55968 KB Output is correct
6 Correct 340 ms 55864 KB Output is correct
7 Correct 342 ms 55608 KB Output is correct
8 Correct 293 ms 55956 KB Output is correct
9 Correct 538 ms 70560 KB Output is correct
10 Correct 744 ms 69120 KB Output is correct
11 Correct 493 ms 56572 KB Output is correct
12 Correct 706 ms 55008 KB Output is correct
13 Correct 543 ms 55752 KB Output is correct
14 Correct 584 ms 56476 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 768 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 1 ms 556 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 2 ms 336 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 506 ms 57120 KB Output is correct
31 Correct 240 ms 57552 KB Output is correct
32 Correct 389 ms 67144 KB Output is correct
33 Correct 345 ms 57252 KB Output is correct
34 Correct 266 ms 56820 KB Output is correct
35 Correct 256 ms 57488 KB Output is correct
36 Correct 208 ms 57904 KB Output is correct
37 Correct 507 ms 71856 KB Output is correct
38 Correct 288 ms 71224 KB Output is correct
39 Correct 469 ms 56936 KB Output is correct
40 Correct 228 ms 57408 KB Output is correct
41 Correct 180 ms 57652 KB Output is correct
42 Correct 182 ms 58284 KB Output is correct
43 Correct 198 ms 57540 KB Output is correct
44 Correct 190 ms 58008 KB Output is correct
45 Correct 194 ms 58680 KB Output is correct
46 Correct 1 ms 336 KB Output is correct
47 Correct 1 ms 336 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 1 ms 336 KB Output is correct
50 Correct 2 ms 508 KB Output is correct
51 Correct 1 ms 504 KB Output is correct
52 Correct 499 ms 56920 KB Output is correct
53 Correct 274 ms 57408 KB Output is correct
54 Correct 460 ms 71668 KB Output is correct
55 Correct 402 ms 57148 KB Output is correct
56 Correct 245 ms 57400 KB Output is correct
57 Correct 248 ms 57108 KB Output is correct
58 Correct 206 ms 58028 KB Output is correct
59 Correct 502 ms 67384 KB Output is correct
60 Correct 287 ms 71268 KB Output is correct
61 Correct 448 ms 57152 KB Output is correct
62 Correct 261 ms 57400 KB Output is correct
63 Correct 1 ms 336 KB Output is correct
64 Correct 1 ms 336 KB Output is correct
65 Correct 1 ms 336 KB Output is correct
66 Correct 1 ms 336 KB Output is correct
67 Correct 1 ms 560 KB Output is correct
68 Correct 1 ms 592 KB Output is correct
69 Correct 1 ms 464 KB Output is correct
70 Correct 1 ms 336 KB Output is correct
71 Correct 1 ms 336 KB Output is correct
72 Correct 1 ms 336 KB Output is correct
73 Correct 1 ms 504 KB Output is correct
74 Correct 2 ms 336 KB Output is correct
75 Correct 1 ms 336 KB Output is correct
76 Correct 1 ms 336 KB Output is correct
77 Correct 1 ms 336 KB Output is correct
78 Correct 1 ms 336 KB Output is correct
79 Correct 616 ms 68924 KB Output is correct
80 Correct 832 ms 65896 KB Output is correct
81 Correct 521 ms 66104 KB Output is correct
82 Correct 484 ms 54228 KB Output is correct
83 Correct 371 ms 54380 KB Output is correct
84 Correct 335 ms 54440 KB Output is correct
85 Correct 268 ms 54980 KB Output is correct
86 Correct 638 ms 64428 KB Output is correct
87 Correct 849 ms 68152 KB Output is correct
88 Correct 577 ms 53816 KB Output is correct
89 Correct 729 ms 54840 KB Output is correct
90 Correct 570 ms 55608 KB Output is correct
91 Correct 527 ms 56168 KB Output is correct
92 Correct 1 ms 336 KB Output is correct
93 Correct 1 ms 336 KB Output is correct
94 Correct 1 ms 336 KB Output is correct
95 Correct 1 ms 336 KB Output is correct
96 Correct 1 ms 460 KB Output is correct
97 Correct 1 ms 460 KB Output is correct
98 Correct 603 ms 66580 KB Output is correct
99 Correct 908 ms 62820 KB Output is correct
100 Correct 575 ms 64848 KB Output is correct
101 Correct 498 ms 55968 KB Output is correct
102 Correct 340 ms 55864 KB Output is correct
103 Correct 342 ms 55608 KB Output is correct
104 Correct 293 ms 55956 KB Output is correct
105 Correct 538 ms 70560 KB Output is correct
106 Correct 744 ms 69120 KB Output is correct
107 Correct 493 ms 56572 KB Output is correct
108 Correct 706 ms 55008 KB Output is correct
109 Correct 543 ms 55752 KB Output is correct
110 Correct 584 ms 56476 KB Output is correct
111 Correct 1 ms 336 KB Output is correct
112 Correct 1 ms 336 KB Output is correct
113 Correct 1 ms 336 KB Output is correct
114 Correct 1 ms 468 KB Output is correct
115 Correct 1 ms 336 KB Output is correct
116 Correct 544 ms 55104 KB Output is correct
117 Correct 681 ms 57660 KB Output is correct
118 Correct 598 ms 71480 KB Output is correct
119 Correct 583 ms 57268 KB Output is correct
120 Correct 333 ms 56844 KB Output is correct
121 Correct 361 ms 57760 KB Output is correct
122 Correct 265 ms 57976 KB Output is correct
123 Correct 524 ms 68828 KB Output is correct
124 Correct 1022 ms 66348 KB Output is correct
125 Correct 507 ms 56120 KB Output is correct
126 Correct 743 ms 57528 KB Output is correct
127 Correct 716 ms 57948 KB Output is correct
128 Correct 552 ms 58732 KB Output is correct
129 Correct 554 ms 59100 KB Output is correct