Submission #561739

# Submission time Handle Problem Language Result Execution time Memory
561739 2022-05-13T12:24:49 Z Jomnoi Sprinkler (JOI22_sprinkler) C++17
100 / 100
851 ms 99572 KB
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 2e5 + 5;
const int MAX_D = 45;

int N, L;
int H[MAX_N];
vector <int> graph[MAX_N];
int parent[MAX_N];
long long keep[MAX_N][MAX_D];

void dfs(int u, int p) {
    for(auto v : graph[u]) {
        if(v != p) {
            parent[v] = u;
            dfs(v, u);
        }
    }
}

void update(int u, int d, int w) {
    while(u != 1 and d >= 0) {
        keep[u][d] = (keep[u][d] * w) % L;

        u = parent[u];
        d--;
    }
    while(d >= 0) {
        keep[1][d] = (keep[1][d] * w) % L;
        d--;
    }
}

int query(int u) {
    long long res = H[u];
    int d = 0;
    while(u != 0 and d <= 40) {
        res = (res * keep[u][d]) % L;
        if(u != 1 and d < 40) {
            res = (res * keep[u][d + 1]) % L;
        }

        u = parent[u];
        d++;
    }
    return res;
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    cin >> N >> L;

    for(int i = 1; i <= N - 1; i++) {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    for(int i = 1; i <= N; i++) {
        cin >> H[i];
    }

    dfs(1, 0);

    for(int i = 0; i < MAX_N; i++) {
        for(int j = 0; j < MAX_D; j++) {
            keep[i][j] = 1;
        }
    }

    int Q;
    cin >> Q;

    while(Q--) {
        int t;
        cin >> t;

        if(t == 1) {
            int x, d, w;
            cin >> x >> d >> w;

            update(x, d, w);
        }
        else {
            int x;
            cin >> x;

            cout << query(x) << '\n';
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 44 ms 75468 KB Output is correct
2 Correct 32 ms 75372 KB Output is correct
3 Correct 33 ms 75336 KB Output is correct
4 Correct 34 ms 75424 KB Output is correct
5 Correct 35 ms 75424 KB Output is correct
6 Correct 40 ms 75496 KB Output is correct
7 Correct 37 ms 75408 KB Output is correct
8 Correct 41 ms 75544 KB Output is correct
9 Correct 34 ms 75388 KB Output is correct
10 Correct 34 ms 75364 KB Output is correct
11 Correct 34 ms 75444 KB Output is correct
12 Correct 33 ms 75392 KB Output is correct
13 Correct 33 ms 75468 KB Output is correct
14 Correct 35 ms 75476 KB Output is correct
15 Correct 36 ms 75396 KB Output is correct
16 Correct 36 ms 75408 KB Output is correct
17 Correct 36 ms 75440 KB Output is correct
18 Correct 34 ms 75456 KB Output is correct
19 Correct 33 ms 75340 KB Output is correct
20 Correct 35 ms 75472 KB Output is correct
21 Correct 34 ms 75428 KB Output is correct
22 Correct 34 ms 75372 KB Output is correct
23 Correct 36 ms 75452 KB Output is correct
24 Correct 37 ms 75412 KB Output is correct
25 Correct 40 ms 75468 KB Output is correct
26 Correct 35 ms 75400 KB Output is correct
27 Correct 33 ms 75428 KB Output is correct
28 Correct 34 ms 75476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 75340 KB Output is correct
2 Correct 780 ms 94804 KB Output is correct
3 Correct 454 ms 91876 KB Output is correct
4 Correct 693 ms 96492 KB Output is correct
5 Correct 535 ms 93352 KB Output is correct
6 Correct 360 ms 90524 KB Output is correct
7 Correct 446 ms 93728 KB Output is correct
8 Correct 271 ms 91544 KB Output is correct
9 Correct 751 ms 98172 KB Output is correct
10 Correct 390 ms 95892 KB Output is correct
11 Correct 668 ms 92032 KB Output is correct
12 Correct 420 ms 90676 KB Output is correct
13 Correct 261 ms 92008 KB Output is correct
14 Correct 353 ms 91868 KB Output is correct
15 Correct 248 ms 85708 KB Output is correct
16 Correct 322 ms 89124 KB Output is correct
17 Correct 286 ms 90416 KB Output is correct
18 Correct 36 ms 75436 KB Output is correct
19 Correct 34 ms 75476 KB Output is correct
20 Correct 41 ms 75444 KB Output is correct
21 Correct 37 ms 75356 KB Output is correct
22 Correct 46 ms 75384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 75340 KB Output is correct
2 Correct 780 ms 94804 KB Output is correct
3 Correct 454 ms 91876 KB Output is correct
4 Correct 693 ms 96492 KB Output is correct
5 Correct 535 ms 93352 KB Output is correct
6 Correct 360 ms 90524 KB Output is correct
7 Correct 446 ms 93728 KB Output is correct
8 Correct 271 ms 91544 KB Output is correct
9 Correct 751 ms 98172 KB Output is correct
10 Correct 390 ms 95892 KB Output is correct
11 Correct 668 ms 92032 KB Output is correct
12 Correct 420 ms 90676 KB Output is correct
13 Correct 261 ms 92008 KB Output is correct
14 Correct 353 ms 91868 KB Output is correct
15 Correct 248 ms 85708 KB Output is correct
16 Correct 322 ms 89124 KB Output is correct
17 Correct 286 ms 90416 KB Output is correct
18 Correct 36 ms 75436 KB Output is correct
19 Correct 34 ms 75476 KB Output is correct
20 Correct 41 ms 75444 KB Output is correct
21 Correct 37 ms 75356 KB Output is correct
22 Correct 46 ms 75384 KB Output is correct
23 Correct 33 ms 75340 KB Output is correct
24 Correct 730 ms 94052 KB Output is correct
25 Correct 427 ms 94320 KB Output is correct
26 Correct 587 ms 99572 KB Output is correct
27 Correct 597 ms 94552 KB Output is correct
28 Correct 397 ms 95104 KB Output is correct
29 Correct 396 ms 94824 KB Output is correct
30 Correct 310 ms 95140 KB Output is correct
31 Correct 775 ms 97012 KB Output is correct
32 Correct 426 ms 98856 KB Output is correct
33 Correct 788 ms 93944 KB Output is correct
34 Correct 436 ms 93508 KB Output is correct
35 Correct 34 ms 75424 KB Output is correct
36 Correct 34 ms 75380 KB Output is correct
37 Correct 33 ms 75424 KB Output is correct
38 Correct 34 ms 75432 KB Output is correct
39 Correct 34 ms 75476 KB Output is correct
40 Correct 37 ms 75468 KB Output is correct
41 Correct 45 ms 75396 KB Output is correct
42 Correct 35 ms 75416 KB Output is correct
43 Correct 34 ms 75468 KB Output is correct
44 Correct 34 ms 75424 KB Output is correct
45 Correct 37 ms 75428 KB Output is correct
46 Correct 34 ms 75396 KB Output is correct
47 Correct 34 ms 75444 KB Output is correct
48 Correct 36 ms 75472 KB Output is correct
49 Correct 46 ms 75448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 75408 KB Output is correct
2 Correct 803 ms 96012 KB Output is correct
3 Correct 661 ms 95412 KB Output is correct
4 Correct 703 ms 95308 KB Output is correct
5 Correct 589 ms 91912 KB Output is correct
6 Correct 393 ms 91680 KB Output is correct
7 Correct 385 ms 91948 KB Output is correct
8 Correct 314 ms 92308 KB Output is correct
9 Correct 836 ms 95084 KB Output is correct
10 Correct 707 ms 96224 KB Output is correct
11 Correct 706 ms 91496 KB Output is correct
12 Correct 639 ms 92256 KB Output is correct
13 Correct 413 ms 92696 KB Output is correct
14 Correct 459 ms 93760 KB Output is correct
15 Correct 34 ms 75372 KB Output is correct
16 Correct 35 ms 75476 KB Output is correct
17 Correct 43 ms 75412 KB Output is correct
18 Correct 35 ms 75432 KB Output is correct
19 Correct 36 ms 75360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 75420 KB Output is correct
2 Correct 768 ms 96832 KB Output is correct
3 Correct 666 ms 94984 KB Output is correct
4 Correct 642 ms 96012 KB Output is correct
5 Correct 572 ms 93508 KB Output is correct
6 Correct 456 ms 93572 KB Output is correct
7 Correct 410 ms 93268 KB Output is correct
8 Correct 269 ms 93804 KB Output is correct
9 Correct 851 ms 98740 KB Output is correct
10 Correct 691 ms 96632 KB Output is correct
11 Correct 754 ms 94176 KB Output is correct
12 Correct 622 ms 92712 KB Output is correct
13 Correct 417 ms 93644 KB Output is correct
14 Correct 421 ms 94004 KB Output is correct
15 Correct 35 ms 75468 KB Output is correct
16 Correct 34 ms 75416 KB Output is correct
17 Correct 36 ms 75456 KB Output is correct
18 Correct 37 ms 75440 KB Output is correct
19 Correct 36 ms 75468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 75468 KB Output is correct
2 Correct 32 ms 75372 KB Output is correct
3 Correct 33 ms 75336 KB Output is correct
4 Correct 34 ms 75424 KB Output is correct
5 Correct 35 ms 75424 KB Output is correct
6 Correct 40 ms 75496 KB Output is correct
7 Correct 37 ms 75408 KB Output is correct
8 Correct 41 ms 75544 KB Output is correct
9 Correct 34 ms 75388 KB Output is correct
10 Correct 34 ms 75364 KB Output is correct
11 Correct 34 ms 75444 KB Output is correct
12 Correct 33 ms 75392 KB Output is correct
13 Correct 33 ms 75468 KB Output is correct
14 Correct 35 ms 75476 KB Output is correct
15 Correct 36 ms 75396 KB Output is correct
16 Correct 36 ms 75408 KB Output is correct
17 Correct 36 ms 75440 KB Output is correct
18 Correct 34 ms 75456 KB Output is correct
19 Correct 33 ms 75340 KB Output is correct
20 Correct 35 ms 75472 KB Output is correct
21 Correct 34 ms 75428 KB Output is correct
22 Correct 34 ms 75372 KB Output is correct
23 Correct 36 ms 75452 KB Output is correct
24 Correct 37 ms 75412 KB Output is correct
25 Correct 40 ms 75468 KB Output is correct
26 Correct 35 ms 75400 KB Output is correct
27 Correct 33 ms 75428 KB Output is correct
28 Correct 34 ms 75476 KB Output is correct
29 Correct 33 ms 75340 KB Output is correct
30 Correct 780 ms 94804 KB Output is correct
31 Correct 454 ms 91876 KB Output is correct
32 Correct 693 ms 96492 KB Output is correct
33 Correct 535 ms 93352 KB Output is correct
34 Correct 360 ms 90524 KB Output is correct
35 Correct 446 ms 93728 KB Output is correct
36 Correct 271 ms 91544 KB Output is correct
37 Correct 751 ms 98172 KB Output is correct
38 Correct 390 ms 95892 KB Output is correct
39 Correct 668 ms 92032 KB Output is correct
40 Correct 420 ms 90676 KB Output is correct
41 Correct 261 ms 92008 KB Output is correct
42 Correct 353 ms 91868 KB Output is correct
43 Correct 248 ms 85708 KB Output is correct
44 Correct 322 ms 89124 KB Output is correct
45 Correct 286 ms 90416 KB Output is correct
46 Correct 36 ms 75436 KB Output is correct
47 Correct 34 ms 75476 KB Output is correct
48 Correct 41 ms 75444 KB Output is correct
49 Correct 37 ms 75356 KB Output is correct
50 Correct 46 ms 75384 KB Output is correct
51 Correct 33 ms 75340 KB Output is correct
52 Correct 730 ms 94052 KB Output is correct
53 Correct 427 ms 94320 KB Output is correct
54 Correct 587 ms 99572 KB Output is correct
55 Correct 597 ms 94552 KB Output is correct
56 Correct 397 ms 95104 KB Output is correct
57 Correct 396 ms 94824 KB Output is correct
58 Correct 310 ms 95140 KB Output is correct
59 Correct 775 ms 97012 KB Output is correct
60 Correct 426 ms 98856 KB Output is correct
61 Correct 788 ms 93944 KB Output is correct
62 Correct 436 ms 93508 KB Output is correct
63 Correct 34 ms 75424 KB Output is correct
64 Correct 34 ms 75380 KB Output is correct
65 Correct 33 ms 75424 KB Output is correct
66 Correct 34 ms 75432 KB Output is correct
67 Correct 34 ms 75476 KB Output is correct
68 Correct 37 ms 75468 KB Output is correct
69 Correct 45 ms 75396 KB Output is correct
70 Correct 35 ms 75416 KB Output is correct
71 Correct 34 ms 75468 KB Output is correct
72 Correct 34 ms 75424 KB Output is correct
73 Correct 37 ms 75428 KB Output is correct
74 Correct 34 ms 75396 KB Output is correct
75 Correct 34 ms 75444 KB Output is correct
76 Correct 36 ms 75472 KB Output is correct
77 Correct 46 ms 75448 KB Output is correct
78 Correct 44 ms 75408 KB Output is correct
79 Correct 803 ms 96012 KB Output is correct
80 Correct 661 ms 95412 KB Output is correct
81 Correct 703 ms 95308 KB Output is correct
82 Correct 589 ms 91912 KB Output is correct
83 Correct 393 ms 91680 KB Output is correct
84 Correct 385 ms 91948 KB Output is correct
85 Correct 314 ms 92308 KB Output is correct
86 Correct 836 ms 95084 KB Output is correct
87 Correct 707 ms 96224 KB Output is correct
88 Correct 706 ms 91496 KB Output is correct
89 Correct 639 ms 92256 KB Output is correct
90 Correct 413 ms 92696 KB Output is correct
91 Correct 459 ms 93760 KB Output is correct
92 Correct 34 ms 75372 KB Output is correct
93 Correct 35 ms 75476 KB Output is correct
94 Correct 43 ms 75412 KB Output is correct
95 Correct 35 ms 75432 KB Output is correct
96 Correct 36 ms 75360 KB Output is correct
97 Correct 33 ms 75420 KB Output is correct
98 Correct 768 ms 96832 KB Output is correct
99 Correct 666 ms 94984 KB Output is correct
100 Correct 642 ms 96012 KB Output is correct
101 Correct 572 ms 93508 KB Output is correct
102 Correct 456 ms 93572 KB Output is correct
103 Correct 410 ms 93268 KB Output is correct
104 Correct 269 ms 93804 KB Output is correct
105 Correct 851 ms 98740 KB Output is correct
106 Correct 691 ms 96632 KB Output is correct
107 Correct 754 ms 94176 KB Output is correct
108 Correct 622 ms 92712 KB Output is correct
109 Correct 417 ms 93644 KB Output is correct
110 Correct 421 ms 94004 KB Output is correct
111 Correct 35 ms 75468 KB Output is correct
112 Correct 34 ms 75416 KB Output is correct
113 Correct 36 ms 75456 KB Output is correct
114 Correct 37 ms 75440 KB Output is correct
115 Correct 36 ms 75468 KB Output is correct
116 Correct 708 ms 92548 KB Output is correct
117 Correct 668 ms 95272 KB Output is correct
118 Correct 710 ms 98580 KB Output is correct
119 Correct 638 ms 94676 KB Output is correct
120 Correct 506 ms 94352 KB Output is correct
121 Correct 445 ms 95188 KB Output is correct
122 Correct 314 ms 95380 KB Output is correct
123 Correct 812 ms 98436 KB Output is correct
124 Correct 735 ms 98004 KB Output is correct
125 Correct 633 ms 93648 KB Output is correct
126 Correct 621 ms 95012 KB Output is correct
127 Correct 693 ms 95588 KB Output is correct
128 Correct 473 ms 92952 KB Output is correct
129 Correct 462 ms 88872 KB Output is correct