답안 #893209

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
893209 2023-12-26T17:36:23 Z vjudge1 Sprinkler (JOI22_sprinkler) C++17
100 / 100
1132 ms 112628 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(a) a.begin(), a.end()

int mod;
void prod(int &a, int b){
	a = (a * b) % mod;
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n; cin >> n >> mod;
	vector< vector<int> > g(n+1);
	for(int i = 1;i < n; i++){
		int a, b; cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	vector< vector<int> > ans(n+1, vector<int>(42, 1));
	vector<int> up(n+1), h(n+1);
	for(int i = 1;i <= n; i++){
		cin >> h[i];
	}
	function<void(int, int)> dfs=[&](int v, int par){
		up[v] = par;
		for(int to : g[v]){
			if(to == par) continue;
			dfs(to, v);
		}
	};
	dfs(1, -1);
	int q; cin >> q;
	while(q--){
		int t; cin >> t;
		if(t == 1){
			int v, d, w; cin >> v >> d >> w;
			int cur = v;
			while(up[cur] != -1 && d > 0){
				prod(ans[cur][d], w);
				prod(ans[cur][d-1], w);
				cur = up[cur];
				d--;
			}
			while(d >= 0){
				prod(ans[cur][d], w);
				d--;
			}
		}else{
			int v; cin >> v;
			
			int product = h[v];
			for(int i = 0;i <= 40 && v != -1; i++, v = up[v]){
				prod(product, ans[v][i]);
			}
			cout << product << '\n';
			
		}
	}
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 868 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 665 ms 92772 KB Output is correct
3 Correct 394 ms 89628 KB Output is correct
4 Correct 554 ms 101972 KB Output is correct
5 Correct 521 ms 90996 KB Output is correct
6 Correct 329 ms 90984 KB Output is correct
7 Correct 356 ms 91516 KB Output is correct
8 Correct 259 ms 91560 KB Output is correct
9 Correct 770 ms 109720 KB Output is correct
10 Correct 480 ms 105072 KB Output is correct
11 Correct 680 ms 92680 KB Output is correct
12 Correct 331 ms 89536 KB Output is correct
13 Correct 217 ms 89840 KB Output is correct
14 Correct 216 ms 89952 KB Output is correct
15 Correct 214 ms 89756 KB Output is correct
16 Correct 219 ms 89680 KB Output is correct
17 Correct 214 ms 90296 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 665 ms 92772 KB Output is correct
3 Correct 394 ms 89628 KB Output is correct
4 Correct 554 ms 101972 KB Output is correct
5 Correct 521 ms 90996 KB Output is correct
6 Correct 329 ms 90984 KB Output is correct
7 Correct 356 ms 91516 KB Output is correct
8 Correct 259 ms 91560 KB Output is correct
9 Correct 770 ms 109720 KB Output is correct
10 Correct 480 ms 105072 KB Output is correct
11 Correct 680 ms 92680 KB Output is correct
12 Correct 331 ms 89536 KB Output is correct
13 Correct 217 ms 89840 KB Output is correct
14 Correct 216 ms 89952 KB Output is correct
15 Correct 214 ms 89756 KB Output is correct
16 Correct 219 ms 89680 KB Output is correct
17 Correct 214 ms 90296 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 614 ms 92704 KB Output is correct
25 Correct 442 ms 89528 KB Output is correct
26 Correct 820 ms 107492 KB Output is correct
27 Correct 515 ms 91116 KB Output is correct
28 Correct 341 ms 91164 KB Output is correct
29 Correct 348 ms 91356 KB Output is correct
30 Correct 255 ms 91588 KB Output is correct
31 Correct 687 ms 104480 KB Output is correct
32 Correct 407 ms 105320 KB Output is correct
33 Correct 660 ms 92784 KB Output is correct
34 Correct 432 ms 89520 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 768 ms 106856 KB Output is correct
3 Correct 1101 ms 101736 KB Output is correct
4 Correct 772 ms 102984 KB Output is correct
5 Correct 590 ms 89612 KB Output is correct
6 Correct 431 ms 89952 KB Output is correct
7 Correct 364 ms 89752 KB Output is correct
8 Correct 285 ms 90080 KB Output is correct
9 Correct 732 ms 101564 KB Output is correct
10 Correct 1067 ms 104772 KB Output is correct
11 Correct 629 ms 90108 KB Output is correct
12 Correct 851 ms 90452 KB Output is correct
13 Correct 461 ms 95060 KB Output is correct
14 Correct 503 ms 96132 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 715 ms 107860 KB Output is correct
3 Correct 1132 ms 102956 KB Output is correct
4 Correct 679 ms 105556 KB Output is correct
5 Correct 572 ms 95620 KB Output is correct
6 Correct 376 ms 95728 KB Output is correct
7 Correct 339 ms 95828 KB Output is correct
8 Correct 268 ms 95772 KB Output is correct
9 Correct 720 ms 112628 KB Output is correct
10 Correct 961 ms 110676 KB Output is correct
11 Correct 656 ms 96852 KB Output is correct
12 Correct 671 ms 94592 KB Output is correct
13 Correct 429 ms 95312 KB Output is correct
14 Correct 466 ms 96732 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 868 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 665 ms 92772 KB Output is correct
31 Correct 394 ms 89628 KB Output is correct
32 Correct 554 ms 101972 KB Output is correct
33 Correct 521 ms 90996 KB Output is correct
34 Correct 329 ms 90984 KB Output is correct
35 Correct 356 ms 91516 KB Output is correct
36 Correct 259 ms 91560 KB Output is correct
37 Correct 770 ms 109720 KB Output is correct
38 Correct 480 ms 105072 KB Output is correct
39 Correct 680 ms 92680 KB Output is correct
40 Correct 331 ms 89536 KB Output is correct
41 Correct 217 ms 89840 KB Output is correct
42 Correct 216 ms 89952 KB Output is correct
43 Correct 214 ms 89756 KB Output is correct
44 Correct 219 ms 89680 KB Output is correct
45 Correct 214 ms 90296 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 614 ms 92704 KB Output is correct
53 Correct 442 ms 89528 KB Output is correct
54 Correct 820 ms 107492 KB Output is correct
55 Correct 515 ms 91116 KB Output is correct
56 Correct 341 ms 91164 KB Output is correct
57 Correct 348 ms 91356 KB Output is correct
58 Correct 255 ms 91588 KB Output is correct
59 Correct 687 ms 104480 KB Output is correct
60 Correct 407 ms 105320 KB Output is correct
61 Correct 660 ms 92784 KB Output is correct
62 Correct 432 ms 89520 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 1 ms 348 KB Output is correct
74 Correct 1 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 1 ms 344 KB Output is correct
78 Correct 1 ms 600 KB Output is correct
79 Correct 768 ms 106856 KB Output is correct
80 Correct 1101 ms 101736 KB Output is correct
81 Correct 772 ms 102984 KB Output is correct
82 Correct 590 ms 89612 KB Output is correct
83 Correct 431 ms 89952 KB Output is correct
84 Correct 364 ms 89752 KB Output is correct
85 Correct 285 ms 90080 KB Output is correct
86 Correct 732 ms 101564 KB Output is correct
87 Correct 1067 ms 104772 KB Output is correct
88 Correct 629 ms 90108 KB Output is correct
89 Correct 851 ms 90452 KB Output is correct
90 Correct 461 ms 95060 KB Output is correct
91 Correct 503 ms 96132 KB Output is correct
92 Correct 1 ms 600 KB Output is correct
93 Correct 0 ms 348 KB Output is correct
94 Correct 1 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 1 ms 344 KB Output is correct
97 Correct 1 ms 348 KB Output is correct
98 Correct 715 ms 107860 KB Output is correct
99 Correct 1132 ms 102956 KB Output is correct
100 Correct 679 ms 105556 KB Output is correct
101 Correct 572 ms 95620 KB Output is correct
102 Correct 376 ms 95728 KB Output is correct
103 Correct 339 ms 95828 KB Output is correct
104 Correct 268 ms 95772 KB Output is correct
105 Correct 720 ms 112628 KB Output is correct
106 Correct 961 ms 110676 KB Output is correct
107 Correct 656 ms 96852 KB Output is correct
108 Correct 671 ms 94592 KB Output is correct
109 Correct 429 ms 95312 KB Output is correct
110 Correct 466 ms 96732 KB Output is correct
111 Correct 1 ms 348 KB Output is correct
112 Correct 0 ms 348 KB Output is correct
113 Correct 1 ms 348 KB Output is correct
114 Correct 0 ms 348 KB Output is correct
115 Correct 1 ms 348 KB Output is correct
116 Correct 561 ms 95332 KB Output is correct
117 Correct 661 ms 95592 KB Output is correct
118 Correct 700 ms 112560 KB Output is correct
119 Correct 524 ms 96336 KB Output is correct
120 Correct 385 ms 96272 KB Output is correct
121 Correct 366 ms 96728 KB Output is correct
122 Correct 312 ms 97584 KB Output is correct
123 Correct 654 ms 106324 KB Output is correct
124 Correct 896 ms 99600 KB Output is correct
125 Correct 516 ms 91984 KB Output is correct
126 Correct 655 ms 89424 KB Output is correct
127 Correct 656 ms 89552 KB Output is correct
128 Correct 494 ms 90400 KB Output is correct
129 Correct 504 ms 90948 KB Output is correct