답안 #544600

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544600 2022-04-02T13:25:53 Z sidon Sprinkler (JOI22_sprinkler) C++17
100 / 100
837 ms 87052 KB
#include <bits/stdc++.h>
using namespace std;
#define int int64_t

const int Z = 2e5+1, B = 42;

int N, L, H[Z][B], W, res;

#define mul(VL) if((VL *= W) >= L) VL %= L

int p[Z];
vector<int> g[Z];

void dfs(int u) {
	for(const int &v : g[u]) if(v != p[u])
		p[v] = u, dfs(v);
}

signed main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> N >> L;

	for(int i = 1; i < N; ++i) {
		int u, v; cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	dfs(1);

	for(int i = 0; i <= N; ++i)
		fill(H[i], H[i] + B, 1);

	for(int i = 1; i <= N; ++i)
		cin >> H[i][0];

	int Q, T, u, d; cin >> Q;
	for(int i = 1; i <= Q; ++i) {
		cin >> T >> u;
		if(T & 1) {
			cin >> d >> W;

			while(u) {
				mul(H[u][d]);
				if(d) {
					mul(H[u][d-1]);
					--d;
					u = p[u];
				} else break;
			}
			if(!u) {
				while(d) {
					mul(H[0][d]);
					--d;
				}
			}
		} else {
			res = H[u][0];
			u = p[u];

			for(d = 1; d < B; ++d) {
				(res *= H[u][d]) %= L;
				if(!u) break;
				u = p[u];
			}
			cout << res << '\n';
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5332 KB Output is correct
5 Correct 4 ms 5332 KB Output is correct
6 Correct 4 ms 5332 KB Output is correct
7 Correct 4 ms 5332 KB Output is correct
8 Correct 4 ms 5332 KB Output is correct
9 Correct 3 ms 5040 KB Output is correct
10 Correct 3 ms 5044 KB Output is correct
11 Correct 4 ms 5012 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5004 KB Output is correct
15 Correct 3 ms 5016 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5036 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 631 ms 83220 KB Output is correct
3 Correct 391 ms 79948 KB Output is correct
4 Correct 591 ms 83952 KB Output is correct
5 Correct 473 ms 81572 KB Output is correct
6 Correct 375 ms 81612 KB Output is correct
7 Correct 338 ms 81936 KB Output is correct
8 Correct 264 ms 82076 KB Output is correct
9 Correct 690 ms 87052 KB Output is correct
10 Correct 393 ms 83684 KB Output is correct
11 Correct 611 ms 83276 KB Output is correct
12 Correct 395 ms 79948 KB Output is correct
13 Correct 257 ms 80396 KB Output is correct
14 Correct 247 ms 80468 KB Output is correct
15 Correct 248 ms 80332 KB Output is correct
16 Correct 248 ms 80288 KB Output is correct
17 Correct 294 ms 80840 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 631 ms 83220 KB Output is correct
3 Correct 391 ms 79948 KB Output is correct
4 Correct 591 ms 83952 KB Output is correct
5 Correct 473 ms 81572 KB Output is correct
6 Correct 375 ms 81612 KB Output is correct
7 Correct 338 ms 81936 KB Output is correct
8 Correct 264 ms 82076 KB Output is correct
9 Correct 690 ms 87052 KB Output is correct
10 Correct 393 ms 83684 KB Output is correct
11 Correct 611 ms 83276 KB Output is correct
12 Correct 395 ms 79948 KB Output is correct
13 Correct 257 ms 80396 KB Output is correct
14 Correct 247 ms 80468 KB Output is correct
15 Correct 248 ms 80332 KB Output is correct
16 Correct 248 ms 80288 KB Output is correct
17 Correct 294 ms 80840 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 687 ms 83208 KB Output is correct
25 Correct 398 ms 80036 KB Output is correct
26 Correct 567 ms 85492 KB Output is correct
27 Correct 518 ms 81584 KB Output is correct
28 Correct 387 ms 81776 KB Output is correct
29 Correct 321 ms 81724 KB Output is correct
30 Correct 308 ms 82088 KB Output is correct
31 Correct 676 ms 85692 KB Output is correct
32 Correct 412 ms 83584 KB Output is correct
33 Correct 680 ms 83180 KB Output is correct
34 Correct 431 ms 80048 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 3 ms 4948 KB Output is correct
41 Correct 3 ms 4948 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 3 ms 4948 KB Output is correct
44 Correct 3 ms 4936 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 698 ms 84620 KB Output is correct
3 Correct 749 ms 82424 KB Output is correct
4 Correct 629 ms 83024 KB Output is correct
5 Correct 559 ms 80124 KB Output is correct
6 Correct 398 ms 80204 KB Output is correct
7 Correct 357 ms 80336 KB Output is correct
8 Correct 266 ms 80556 KB Output is correct
9 Correct 682 ms 83020 KB Output is correct
10 Correct 825 ms 83320 KB Output is correct
11 Correct 699 ms 80300 KB Output is correct
12 Correct 672 ms 79772 KB Output is correct
13 Correct 431 ms 80608 KB Output is correct
14 Correct 473 ms 81468 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 4 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 708 ms 85432 KB Output is correct
3 Correct 790 ms 81516 KB Output is correct
4 Correct 669 ms 83684 KB Output is correct
5 Correct 583 ms 81636 KB Output is correct
6 Correct 440 ms 81668 KB Output is correct
7 Correct 428 ms 81764 KB Output is correct
8 Correct 265 ms 81932 KB Output is correct
9 Correct 723 ms 86676 KB Output is correct
10 Correct 829 ms 83660 KB Output is correct
11 Correct 672 ms 83064 KB Output is correct
12 Correct 611 ms 79928 KB Output is correct
13 Correct 516 ms 80712 KB Output is correct
14 Correct 456 ms 81576 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 5332 KB Output is correct
5 Correct 4 ms 5332 KB Output is correct
6 Correct 4 ms 5332 KB Output is correct
7 Correct 4 ms 5332 KB Output is correct
8 Correct 4 ms 5332 KB Output is correct
9 Correct 3 ms 5040 KB Output is correct
10 Correct 3 ms 5044 KB Output is correct
11 Correct 4 ms 5012 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5004 KB Output is correct
15 Correct 3 ms 5016 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5036 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 631 ms 83220 KB Output is correct
31 Correct 391 ms 79948 KB Output is correct
32 Correct 591 ms 83952 KB Output is correct
33 Correct 473 ms 81572 KB Output is correct
34 Correct 375 ms 81612 KB Output is correct
35 Correct 338 ms 81936 KB Output is correct
36 Correct 264 ms 82076 KB Output is correct
37 Correct 690 ms 87052 KB Output is correct
38 Correct 393 ms 83684 KB Output is correct
39 Correct 611 ms 83276 KB Output is correct
40 Correct 395 ms 79948 KB Output is correct
41 Correct 257 ms 80396 KB Output is correct
42 Correct 247 ms 80468 KB Output is correct
43 Correct 248 ms 80332 KB Output is correct
44 Correct 248 ms 80288 KB Output is correct
45 Correct 294 ms 80840 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 2 ms 4948 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 687 ms 83208 KB Output is correct
53 Correct 398 ms 80036 KB Output is correct
54 Correct 567 ms 85492 KB Output is correct
55 Correct 518 ms 81584 KB Output is correct
56 Correct 387 ms 81776 KB Output is correct
57 Correct 321 ms 81724 KB Output is correct
58 Correct 308 ms 82088 KB Output is correct
59 Correct 676 ms 85692 KB Output is correct
60 Correct 412 ms 83584 KB Output is correct
61 Correct 680 ms 83180 KB Output is correct
62 Correct 431 ms 80048 KB Output is correct
63 Correct 3 ms 4948 KB Output is correct
64 Correct 3 ms 4948 KB Output is correct
65 Correct 3 ms 4948 KB Output is correct
66 Correct 3 ms 4948 KB Output is correct
67 Correct 3 ms 4948 KB Output is correct
68 Correct 3 ms 4948 KB Output is correct
69 Correct 3 ms 4948 KB Output is correct
70 Correct 3 ms 4948 KB Output is correct
71 Correct 3 ms 4948 KB Output is correct
72 Correct 3 ms 4936 KB Output is correct
73 Correct 3 ms 4948 KB Output is correct
74 Correct 3 ms 4948 KB Output is correct
75 Correct 3 ms 4948 KB Output is correct
76 Correct 3 ms 4948 KB Output is correct
77 Correct 3 ms 4948 KB Output is correct
78 Correct 3 ms 4948 KB Output is correct
79 Correct 698 ms 84620 KB Output is correct
80 Correct 749 ms 82424 KB Output is correct
81 Correct 629 ms 83024 KB Output is correct
82 Correct 559 ms 80124 KB Output is correct
83 Correct 398 ms 80204 KB Output is correct
84 Correct 357 ms 80336 KB Output is correct
85 Correct 266 ms 80556 KB Output is correct
86 Correct 682 ms 83020 KB Output is correct
87 Correct 825 ms 83320 KB Output is correct
88 Correct 699 ms 80300 KB Output is correct
89 Correct 672 ms 79772 KB Output is correct
90 Correct 431 ms 80608 KB Output is correct
91 Correct 473 ms 81468 KB Output is correct
92 Correct 3 ms 4948 KB Output is correct
93 Correct 3 ms 4948 KB Output is correct
94 Correct 4 ms 4948 KB Output is correct
95 Correct 3 ms 4948 KB Output is correct
96 Correct 4 ms 4948 KB Output is correct
97 Correct 3 ms 4948 KB Output is correct
98 Correct 708 ms 85432 KB Output is correct
99 Correct 790 ms 81516 KB Output is correct
100 Correct 669 ms 83684 KB Output is correct
101 Correct 583 ms 81636 KB Output is correct
102 Correct 440 ms 81668 KB Output is correct
103 Correct 428 ms 81764 KB Output is correct
104 Correct 265 ms 81932 KB Output is correct
105 Correct 723 ms 86676 KB Output is correct
106 Correct 829 ms 83660 KB Output is correct
107 Correct 672 ms 83064 KB Output is correct
108 Correct 611 ms 79928 KB Output is correct
109 Correct 516 ms 80712 KB Output is correct
110 Correct 456 ms 81576 KB Output is correct
111 Correct 3 ms 4948 KB Output is correct
112 Correct 3 ms 4948 KB Output is correct
113 Correct 3 ms 4948 KB Output is correct
114 Correct 4 ms 4948 KB Output is correct
115 Correct 3 ms 4948 KB Output is correct
116 Correct 628 ms 81240 KB Output is correct
117 Correct 715 ms 79784 KB Output is correct
118 Correct 604 ms 85256 KB Output is correct
119 Correct 682 ms 81564 KB Output is correct
120 Correct 467 ms 81612 KB Output is correct
121 Correct 405 ms 81948 KB Output is correct
122 Correct 317 ms 82148 KB Output is correct
123 Correct 757 ms 86236 KB Output is correct
124 Correct 837 ms 82024 KB Output is correct
125 Correct 661 ms 82540 KB Output is correct
126 Correct 741 ms 79820 KB Output is correct
127 Correct 757 ms 79920 KB Output is correct
128 Correct 557 ms 80824 KB Output is correct
129 Correct 568 ms 81612 KB Output is correct