답안 #576256

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
576256 2022-06-12T18:57:47 Z erekle Sprinkler (JOI22_sprinkler) C++17
100 / 100
2128 ms 72740 KB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int MAX_D = 40;

int n;
vector<vector<int>> g;
vector<int> parent;
void dfs(int i) {
    for (int j : g[i]) {
        if (!parent[j]) parent[j] = i, dfs(j);
    }
}

int main() {
    int l;
    cin >> n >> l;
    g.resize(1+n);
    for (int i = 1; i < n; ++i) {
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    parent.resize(1+n);
    parent[1] = -1;
    dfs(1);
    parent[1] = 0;

    vector<int> h(1+n);
    for (int i = 1; i <= n; ++i) cin >> h[i];

    vector<vector<int>> multiplyDown(1+n, vector<int>(1+MAX_D, 1));
    // all nodes distance j below node i need to be multiplied by multiplyDown[i][j]
    int q; cin >> q;
    while (q--) {
        int t, x; cin >> t >> x;
        if (t == 1) {
            int d, w;
            // we do not want same node to be multiplied by multiple ancestors
            // so every node will only be multiplied by the highest node that can multiply it
            for (cin >> d >> w; d >= 0 && x; --d, x = parent[x]) {
                multiplyDown[x][d] = (long long)multiplyDown[x][d] * w % l;
                if (d) multiplyDown[x][d-1] = (long long)multiplyDown[x][d-1] * w % l;
                if (!parent[x]) {
                    for (int k = d-2; k >= 0; --k) {
                        multiplyDown[x][k] = (long long)multiplyDown[x][k] * w % l;
                    }
                }
            }
        } else {
            int v = h[x];
            for (int d = 0; d <= MAX_D && x; ++d, x = parent[x]) {
                v = (long long)v * multiplyDown[x][d] % l;
            }
            cout << v << endl;
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 3 ms 528 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 2 ms 212 KB Output is correct
14 Correct 2 ms 240 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 308 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 300 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 2 ms 312 KB Output is correct
27 Correct 2 ms 212 KB Output is correct
28 Correct 1 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1280 ms 63736 KB Output is correct
3 Correct 807 ms 64268 KB Output is correct
4 Correct 1093 ms 69836 KB Output is correct
5 Correct 1038 ms 64076 KB Output is correct
6 Correct 942 ms 63040 KB Output is correct
7 Correct 868 ms 64332 KB Output is correct
8 Correct 826 ms 64832 KB Output is correct
9 Correct 1360 ms 72740 KB Output is correct
10 Correct 840 ms 72448 KB Output is correct
11 Correct 1254 ms 63452 KB Output is correct
12 Correct 793 ms 64384 KB Output is correct
13 Correct 624 ms 64600 KB Output is correct
14 Correct 631 ms 65048 KB Output is correct
15 Correct 616 ms 63328 KB Output is correct
16 Correct 646 ms 65116 KB Output is correct
17 Correct 653 ms 65100 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Correct 2 ms 304 KB Output is correct
22 Correct 2 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1280 ms 63736 KB Output is correct
3 Correct 807 ms 64268 KB Output is correct
4 Correct 1093 ms 69836 KB Output is correct
5 Correct 1038 ms 64076 KB Output is correct
6 Correct 942 ms 63040 KB Output is correct
7 Correct 868 ms 64332 KB Output is correct
8 Correct 826 ms 64832 KB Output is correct
9 Correct 1360 ms 72740 KB Output is correct
10 Correct 840 ms 72448 KB Output is correct
11 Correct 1254 ms 63452 KB Output is correct
12 Correct 793 ms 64384 KB Output is correct
13 Correct 624 ms 64600 KB Output is correct
14 Correct 631 ms 65048 KB Output is correct
15 Correct 616 ms 63328 KB Output is correct
16 Correct 646 ms 65116 KB Output is correct
17 Correct 653 ms 65100 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Correct 2 ms 304 KB Output is correct
22 Correct 2 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1319 ms 63880 KB Output is correct
25 Correct 839 ms 64380 KB Output is correct
26 Correct 1125 ms 72680 KB Output is correct
27 Correct 1115 ms 63956 KB Output is correct
28 Correct 924 ms 64116 KB Output is correct
29 Correct 870 ms 63836 KB Output is correct
30 Correct 800 ms 64956 KB Output is correct
31 Correct 1405 ms 70124 KB Output is correct
32 Correct 863 ms 72528 KB Output is correct
33 Correct 1282 ms 63760 KB Output is correct
34 Correct 823 ms 64256 KB Output is correct
35 Correct 2 ms 212 KB Output is correct
36 Correct 2 ms 304 KB Output is correct
37 Correct 2 ms 212 KB Output is correct
38 Correct 2 ms 212 KB Output is correct
39 Correct 2 ms 212 KB Output is correct
40 Correct 2 ms 212 KB Output is correct
41 Correct 2 ms 212 KB Output is correct
42 Correct 2 ms 212 KB Output is correct
43 Correct 2 ms 212 KB Output is correct
44 Correct 2 ms 212 KB Output is correct
45 Correct 2 ms 300 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1532 ms 69896 KB Output is correct
3 Correct 2077 ms 68328 KB Output is correct
4 Correct 1423 ms 68404 KB Output is correct
5 Correct 1247 ms 61032 KB Output is correct
6 Correct 969 ms 61120 KB Output is correct
7 Correct 911 ms 61392 KB Output is correct
8 Correct 776 ms 61916 KB Output is correct
9 Correct 1515 ms 67144 KB Output is correct
10 Correct 2033 ms 69596 KB Output is correct
11 Correct 1360 ms 60732 KB Output is correct
12 Correct 1592 ms 61548 KB Output is correct
13 Correct 1074 ms 62580 KB Output is correct
14 Correct 1177 ms 63288 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1579 ms 69404 KB Output is correct
3 Correct 2017 ms 66740 KB Output is correct
4 Correct 1487 ms 67952 KB Output is correct
5 Correct 1299 ms 62836 KB Output is correct
6 Correct 1089 ms 62728 KB Output is correct
7 Correct 942 ms 62468 KB Output is correct
8 Correct 772 ms 62984 KB Output is correct
9 Correct 1517 ms 71880 KB Output is correct
10 Correct 2073 ms 70720 KB Output is correct
11 Correct 1366 ms 63500 KB Output is correct
12 Correct 1591 ms 62048 KB Output is correct
13 Correct 1088 ms 62740 KB Output is correct
14 Correct 1158 ms 63248 KB Output is correct
15 Correct 2 ms 304 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 2 ms 300 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 3 ms 528 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 2 ms 212 KB Output is correct
14 Correct 2 ms 240 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 308 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 300 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 2 ms 312 KB Output is correct
27 Correct 2 ms 212 KB Output is correct
28 Correct 1 ms 296 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1280 ms 63736 KB Output is correct
31 Correct 807 ms 64268 KB Output is correct
32 Correct 1093 ms 69836 KB Output is correct
33 Correct 1038 ms 64076 KB Output is correct
34 Correct 942 ms 63040 KB Output is correct
35 Correct 868 ms 64332 KB Output is correct
36 Correct 826 ms 64832 KB Output is correct
37 Correct 1360 ms 72740 KB Output is correct
38 Correct 840 ms 72448 KB Output is correct
39 Correct 1254 ms 63452 KB Output is correct
40 Correct 793 ms 64384 KB Output is correct
41 Correct 624 ms 64600 KB Output is correct
42 Correct 631 ms 65048 KB Output is correct
43 Correct 616 ms 63328 KB Output is correct
44 Correct 646 ms 65116 KB Output is correct
45 Correct 653 ms 65100 KB Output is correct
46 Correct 2 ms 212 KB Output is correct
47 Correct 2 ms 212 KB Output is correct
48 Correct 2 ms 212 KB Output is correct
49 Correct 2 ms 304 KB Output is correct
50 Correct 2 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1319 ms 63880 KB Output is correct
53 Correct 839 ms 64380 KB Output is correct
54 Correct 1125 ms 72680 KB Output is correct
55 Correct 1115 ms 63956 KB Output is correct
56 Correct 924 ms 64116 KB Output is correct
57 Correct 870 ms 63836 KB Output is correct
58 Correct 800 ms 64956 KB Output is correct
59 Correct 1405 ms 70124 KB Output is correct
60 Correct 863 ms 72528 KB Output is correct
61 Correct 1282 ms 63760 KB Output is correct
62 Correct 823 ms 64256 KB Output is correct
63 Correct 2 ms 212 KB Output is correct
64 Correct 2 ms 304 KB Output is correct
65 Correct 2 ms 212 KB Output is correct
66 Correct 2 ms 212 KB Output is correct
67 Correct 2 ms 212 KB Output is correct
68 Correct 2 ms 212 KB Output is correct
69 Correct 2 ms 212 KB Output is correct
70 Correct 2 ms 212 KB Output is correct
71 Correct 2 ms 212 KB Output is correct
72 Correct 2 ms 212 KB Output is correct
73 Correct 2 ms 300 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 2 ms 340 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 1532 ms 69896 KB Output is correct
80 Correct 2077 ms 68328 KB Output is correct
81 Correct 1423 ms 68404 KB Output is correct
82 Correct 1247 ms 61032 KB Output is correct
83 Correct 969 ms 61120 KB Output is correct
84 Correct 911 ms 61392 KB Output is correct
85 Correct 776 ms 61916 KB Output is correct
86 Correct 1515 ms 67144 KB Output is correct
87 Correct 2033 ms 69596 KB Output is correct
88 Correct 1360 ms 60732 KB Output is correct
89 Correct 1592 ms 61548 KB Output is correct
90 Correct 1074 ms 62580 KB Output is correct
91 Correct 1177 ms 63288 KB Output is correct
92 Correct 2 ms 212 KB Output is correct
93 Correct 1 ms 212 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 0 ms 212 KB Output is correct
98 Correct 1579 ms 69404 KB Output is correct
99 Correct 2017 ms 66740 KB Output is correct
100 Correct 1487 ms 67952 KB Output is correct
101 Correct 1299 ms 62836 KB Output is correct
102 Correct 1089 ms 62728 KB Output is correct
103 Correct 942 ms 62468 KB Output is correct
104 Correct 772 ms 62984 KB Output is correct
105 Correct 1517 ms 71880 KB Output is correct
106 Correct 2073 ms 70720 KB Output is correct
107 Correct 1366 ms 63500 KB Output is correct
108 Correct 1591 ms 62048 KB Output is correct
109 Correct 1088 ms 62740 KB Output is correct
110 Correct 1158 ms 63248 KB Output is correct
111 Correct 2 ms 304 KB Output is correct
112 Correct 1 ms 212 KB Output is correct
113 Correct 2 ms 212 KB Output is correct
114 Correct 2 ms 300 KB Output is correct
115 Correct 2 ms 212 KB Output is correct
116 Correct 1412 ms 61784 KB Output is correct
117 Correct 1705 ms 64700 KB Output is correct
118 Correct 1485 ms 72504 KB Output is correct
119 Correct 1313 ms 64196 KB Output is correct
120 Correct 1000 ms 63688 KB Output is correct
121 Correct 978 ms 64536 KB Output is correct
122 Correct 953 ms 64768 KB Output is correct
123 Correct 1588 ms 71020 KB Output is correct
124 Correct 2128 ms 69804 KB Output is correct
125 Correct 1410 ms 63116 KB Output is correct
126 Correct 1700 ms 64360 KB Output is correct
127 Correct 1701 ms 65040 KB Output is correct
128 Correct 1166 ms 65456 KB Output is correct
129 Correct 1232 ms 66172 KB Output is correct