답안 #1050798

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050798 2024-08-09T14:37:08 Z 0npata Sprinkler (JOI22_sprinkler) C++17
100 / 100
1412 ms 106672 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define vec vector
#define arr array

const int MXN = 200'005;
const int MXD = 43;

int pars[MXN];
vec<int> tree[MXN];

void dfs0(int u = 0, int p = -1) {
	pars[u] = p;
	for(int v : tree[u]) {
		if(v == p) continue;
		dfs0(v, u);
	}
}

int32_t main() {
	int N, L;
	cin >> N >> L;
	for(int i = 0; i<N-1; i++) {
		int u, v;
		cin >> u >> v;
		u--,v--;
		tree[u].push_back(v);
		tree[v].push_back(u);
	}
	dfs0();
	vec<vec<int>> contr(N, vec<int>(MXD+1, 1));

	for(int i = 0; i<N; i++) {
		int h;
		cin >> h;
		contr[i][0] = h;
	}

	int Q;
	cin >> Q;
	while(Q--) {
		int t, u;
		cin >> t >> u;
		u--;
		if(t==1) {
			int d, m;
			cin >> d >> m;
			while(u != -1 && d >= 0) {
				//cerr <<"UPD: " <<  u << '\n';
				contr[u][d] *= m;
				contr[u][d] %= L;
				u = pars[u];
				d--;
			}
			//cerr <<"----------" << '\n';
			if(false){
			for(int i = 0; i<N; i++) {
				for(int j = 0; j<5; j++) {
					cerr << contr[i][j] << ' ';
				}
				cerr << '\n';
			}
			cerr << '\n';
			}
			//cerr << "------------------" << '\n';
		}
		else {
			assert(t==2);
			int res = 1;
			for(int i = 0; i<MXD && u != -1; i++) {
				for(int j = i; j<((pars[u] == -1) ? (MXD+1) : (i+2)); j++) {
					res *= contr[u][j];
					res %= L;
					//cerr << "MUL: " << res << '\n';
				}
				u = pars[u];
			}
			cout << res << '\n';
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 2 ms 5480 KB Output is correct
5 Correct 2 ms 5412 KB Output is correct
6 Correct 2 ms 5468 KB Output is correct
7 Correct 2 ms 5468 KB Output is correct
8 Correct 2 ms 5468 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 2 ms 5144 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 1 ms 4956 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
25 Correct 1 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 1 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 870 ms 94224 KB Output is correct
3 Correct 448 ms 90960 KB Output is correct
4 Correct 699 ms 95060 KB Output is correct
5 Correct 684 ms 92496 KB Output is correct
6 Correct 562 ms 92500 KB Output is correct
7 Correct 654 ms 92880 KB Output is correct
8 Correct 583 ms 93120 KB Output is correct
9 Correct 1102 ms 98500 KB Output is correct
10 Correct 601 ms 94872 KB Output is correct
11 Correct 1082 ms 97360 KB Output is correct
12 Correct 628 ms 102556 KB Output is correct
13 Correct 412 ms 102588 KB Output is correct
14 Correct 419 ms 102784 KB Output is correct
15 Correct 414 ms 102188 KB Output is correct
16 Correct 417 ms 102780 KB Output is correct
17 Correct 439 ms 103316 KB Output is correct
18 Correct 2 ms 4952 KB Output is correct
19 Correct 3 ms 4952 KB Output is correct
20 Correct 4 ms 4956 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 4 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 870 ms 94224 KB Output is correct
3 Correct 448 ms 90960 KB Output is correct
4 Correct 699 ms 95060 KB Output is correct
5 Correct 684 ms 92496 KB Output is correct
6 Correct 562 ms 92500 KB Output is correct
7 Correct 654 ms 92880 KB Output is correct
8 Correct 583 ms 93120 KB Output is correct
9 Correct 1102 ms 98500 KB Output is correct
10 Correct 601 ms 94872 KB Output is correct
11 Correct 1082 ms 97360 KB Output is correct
12 Correct 628 ms 102556 KB Output is correct
13 Correct 412 ms 102588 KB Output is correct
14 Correct 419 ms 102784 KB Output is correct
15 Correct 414 ms 102188 KB Output is correct
16 Correct 417 ms 102780 KB Output is correct
17 Correct 439 ms 103316 KB Output is correct
18 Correct 2 ms 4952 KB Output is correct
19 Correct 3 ms 4952 KB Output is correct
20 Correct 4 ms 4956 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 4 ms 4956 KB Output is correct
23 Correct 2 ms 4952 KB Output is correct
24 Correct 1168 ms 102240 KB Output is correct
25 Correct 657 ms 102480 KB Output is correct
26 Correct 994 ms 106464 KB Output is correct
27 Correct 910 ms 102192 KB Output is correct
28 Correct 798 ms 102492 KB Output is correct
29 Correct 709 ms 102380 KB Output is correct
30 Correct 641 ms 102852 KB Output is correct
31 Correct 1171 ms 105080 KB Output is correct
32 Correct 713 ms 106672 KB Output is correct
33 Correct 1140 ms 102468 KB Output is correct
34 Correct 675 ms 102484 KB Output is correct
35 Correct 2 ms 4956 KB Output is correct
36 Correct 3 ms 5152 KB Output is correct
37 Correct 3 ms 4956 KB Output is correct
38 Correct 4 ms 4956 KB Output is correct
39 Correct 3 ms 5148 KB Output is correct
40 Correct 3 ms 4956 KB Output is correct
41 Correct 3 ms 4956 KB Output is correct
42 Correct 3 ms 4952 KB Output is correct
43 Correct 6 ms 4952 KB Output is correct
44 Correct 2 ms 5036 KB Output is correct
45 Correct 5 ms 4956 KB Output is correct
46 Correct 4 ms 4956 KB Output is correct
47 Correct 2 ms 4956 KB Output is correct
48 Correct 2 ms 4956 KB Output is correct
49 Correct 2 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 1412 ms 103788 KB Output is correct
3 Correct 1130 ms 103200 KB Output is correct
4 Correct 1125 ms 102736 KB Output is correct
5 Correct 1090 ms 99616 KB Output is correct
6 Correct 763 ms 99920 KB Output is correct
7 Correct 727 ms 100084 KB Output is correct
8 Correct 618 ms 100348 KB Output is correct
9 Correct 1192 ms 102076 KB Output is correct
10 Correct 1064 ms 103768 KB Output is correct
11 Correct 1083 ms 99408 KB Output is correct
12 Correct 942 ms 100204 KB Output is correct
13 Correct 611 ms 101340 KB Output is correct
14 Correct 640 ms 101988 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 4 ms 5032 KB Output is correct
18 Correct 3 ms 4956 KB Output is correct
19 Correct 4 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 1151 ms 104512 KB Output is correct
3 Correct 939 ms 102308 KB Output is correct
4 Correct 824 ms 103252 KB Output is correct
5 Correct 773 ms 101204 KB Output is correct
6 Correct 598 ms 101456 KB Output is correct
7 Correct 578 ms 101300 KB Output is correct
8 Correct 523 ms 101312 KB Output is correct
9 Correct 1072 ms 105884 KB Output is correct
10 Correct 795 ms 104408 KB Output is correct
11 Correct 1008 ms 102012 KB Output is correct
12 Correct 706 ms 100432 KB Output is correct
13 Correct 521 ms 101204 KB Output is correct
14 Correct 542 ms 102180 KB Output is correct
15 Correct 2 ms 4952 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 2 ms 5480 KB Output is correct
5 Correct 2 ms 5412 KB Output is correct
6 Correct 2 ms 5468 KB Output is correct
7 Correct 2 ms 5468 KB Output is correct
8 Correct 2 ms 5468 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 2 ms 5144 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 1 ms 4956 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
25 Correct 1 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 1 ms 4956 KB Output is correct
29 Correct 1 ms 4956 KB Output is correct
30 Correct 870 ms 94224 KB Output is correct
31 Correct 448 ms 90960 KB Output is correct
32 Correct 699 ms 95060 KB Output is correct
33 Correct 684 ms 92496 KB Output is correct
34 Correct 562 ms 92500 KB Output is correct
35 Correct 654 ms 92880 KB Output is correct
36 Correct 583 ms 93120 KB Output is correct
37 Correct 1102 ms 98500 KB Output is correct
38 Correct 601 ms 94872 KB Output is correct
39 Correct 1082 ms 97360 KB Output is correct
40 Correct 628 ms 102556 KB Output is correct
41 Correct 412 ms 102588 KB Output is correct
42 Correct 419 ms 102784 KB Output is correct
43 Correct 414 ms 102188 KB Output is correct
44 Correct 417 ms 102780 KB Output is correct
45 Correct 439 ms 103316 KB Output is correct
46 Correct 2 ms 4952 KB Output is correct
47 Correct 3 ms 4952 KB Output is correct
48 Correct 4 ms 4956 KB Output is correct
49 Correct 3 ms 4956 KB Output is correct
50 Correct 4 ms 4956 KB Output is correct
51 Correct 2 ms 4952 KB Output is correct
52 Correct 1168 ms 102240 KB Output is correct
53 Correct 657 ms 102480 KB Output is correct
54 Correct 994 ms 106464 KB Output is correct
55 Correct 910 ms 102192 KB Output is correct
56 Correct 798 ms 102492 KB Output is correct
57 Correct 709 ms 102380 KB Output is correct
58 Correct 641 ms 102852 KB Output is correct
59 Correct 1171 ms 105080 KB Output is correct
60 Correct 713 ms 106672 KB Output is correct
61 Correct 1140 ms 102468 KB Output is correct
62 Correct 675 ms 102484 KB Output is correct
63 Correct 2 ms 4956 KB Output is correct
64 Correct 3 ms 5152 KB Output is correct
65 Correct 3 ms 4956 KB Output is correct
66 Correct 4 ms 4956 KB Output is correct
67 Correct 3 ms 5148 KB Output is correct
68 Correct 3 ms 4956 KB Output is correct
69 Correct 3 ms 4956 KB Output is correct
70 Correct 3 ms 4952 KB Output is correct
71 Correct 6 ms 4952 KB Output is correct
72 Correct 2 ms 5036 KB Output is correct
73 Correct 5 ms 4956 KB Output is correct
74 Correct 4 ms 4956 KB Output is correct
75 Correct 2 ms 4956 KB Output is correct
76 Correct 2 ms 4956 KB Output is correct
77 Correct 2 ms 4956 KB Output is correct
78 Correct 2 ms 4956 KB Output is correct
79 Correct 1412 ms 103788 KB Output is correct
80 Correct 1130 ms 103200 KB Output is correct
81 Correct 1125 ms 102736 KB Output is correct
82 Correct 1090 ms 99616 KB Output is correct
83 Correct 763 ms 99920 KB Output is correct
84 Correct 727 ms 100084 KB Output is correct
85 Correct 618 ms 100348 KB Output is correct
86 Correct 1192 ms 102076 KB Output is correct
87 Correct 1064 ms 103768 KB Output is correct
88 Correct 1083 ms 99408 KB Output is correct
89 Correct 942 ms 100204 KB Output is correct
90 Correct 611 ms 101340 KB Output is correct
91 Correct 640 ms 101988 KB Output is correct
92 Correct 2 ms 4956 KB Output is correct
93 Correct 3 ms 4956 KB Output is correct
94 Correct 4 ms 5032 KB Output is correct
95 Correct 3 ms 4956 KB Output is correct
96 Correct 4 ms 4956 KB Output is correct
97 Correct 2 ms 4956 KB Output is correct
98 Correct 1151 ms 104512 KB Output is correct
99 Correct 939 ms 102308 KB Output is correct
100 Correct 824 ms 103252 KB Output is correct
101 Correct 773 ms 101204 KB Output is correct
102 Correct 598 ms 101456 KB Output is correct
103 Correct 578 ms 101300 KB Output is correct
104 Correct 523 ms 101312 KB Output is correct
105 Correct 1072 ms 105884 KB Output is correct
106 Correct 795 ms 104408 KB Output is correct
107 Correct 1008 ms 102012 KB Output is correct
108 Correct 706 ms 100432 KB Output is correct
109 Correct 521 ms 101204 KB Output is correct
110 Correct 542 ms 102180 KB Output is correct
111 Correct 2 ms 4952 KB Output is correct
112 Correct 2 ms 4956 KB Output is correct
113 Correct 1 ms 4956 KB Output is correct
114 Correct 2 ms 4956 KB Output is correct
115 Correct 1 ms 4956 KB Output is correct
116 Correct 938 ms 100436 KB Output is correct
117 Correct 814 ms 102980 KB Output is correct
118 Correct 816 ms 106576 KB Output is correct
119 Correct 760 ms 102740 KB Output is correct
120 Correct 635 ms 102224 KB Output is correct
121 Correct 609 ms 103252 KB Output is correct
122 Correct 539 ms 103084 KB Output is correct
123 Correct 1026 ms 105640 KB Output is correct
124 Correct 823 ms 104788 KB Output is correct
125 Correct 944 ms 101536 KB Output is correct
126 Correct 716 ms 102844 KB Output is correct
127 Correct 784 ms 103268 KB Output is correct
128 Correct 574 ms 104120 KB Output is correct
129 Correct 630 ms 104784 KB Output is correct