Submission #544546

# Submission time Handle Problem Language Result Execution time Memory
544546 2022-04-02T09:32:41 Z benson1029 Sprinkler (JOI22_sprinkler) C++14
100 / 100
1259 ms 85632 KB
#include<bits/stdc++.h>
using namespace std;

int n, l, s, t;
vector<int> edg[200045];
long long h[200045];
int q;
int op, x, d, k;
int anc[200045];
long long v[200045][41];

void dfs(int x, int p) {
	anc[x] = p;
	for(int i:edg[x]) {
		if(i!=p) {
			dfs(i, x);
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> l;
	for(int i=0; i<n-1; i++) {
		cin >> s >> t;
		edg[s].push_back(t);
		edg[t].push_back(s);
	}
	for(int i=1; i<=n; i++) {
		cin >> h[i];
	}
	for(int i=n+1; i<n+40; i++) {
		edg[i].push_back(i+1);
	}
	edg[n+40].push_back(1);
	dfs(n+1, -1);
	cin >> q; 
	for(int i=1; i<=n+40; i++) {
		for(int j=0; j<=40; j++) {
			v[i][j] = 1;
		}
	}
	while(q--) {
		cin >> op >> x;
		if(op==1) {
			cin >> d >> k;
			int ptr = x;
			for(int i=0; i<=d; i++) {
				v[ptr][d-i] = (v[ptr][d-i] * k) % l;
				if(i<d) v[ptr][d-1-i] = (v[ptr][d-1-i] * k) % l;
				ptr = anc[ptr];
			}
		} else {
			int ptr = x;
			long long ans = h[x];
			for(int i=0; i<=40; i++) {
				ans = (ans * v[ptr][i]) % l;
				ptr = anc[ptr];
			}
			cout << ans << "\n";
		}
	}
} 
# Verdict Execution time Memory 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 4 ms 5332 KB Output is correct
5 Correct 4 ms 5332 KB Output is correct
6 Correct 5 ms 5332 KB Output is correct
7 Correct 5 ms 5340 KB Output is correct
8 Correct 4 ms 5332 KB Output is correct
9 Correct 4 ms 5024 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 4 ms 5068 KB Output is correct
12 Correct 4 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 4 ms 4948 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 4944 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 4 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 4 ms 4948 KB Output is correct
26 Correct 4 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 956 ms 81568 KB Output is correct
3 Correct 441 ms 78268 KB Output is correct
4 Correct 709 ms 82744 KB Output is correct
5 Correct 695 ms 79832 KB Output is correct
6 Correct 596 ms 80984 KB Output is correct
7 Correct 577 ms 80084 KB Output is correct
8 Correct 535 ms 80576 KB Output is correct
9 Correct 1022 ms 85632 KB Output is correct
10 Correct 419 ms 82252 KB Output is correct
11 Correct 970 ms 81416 KB Output is correct
12 Correct 396 ms 78396 KB Output is correct
13 Correct 292 ms 78852 KB Output is correct
14 Correct 299 ms 78836 KB Output is correct
15 Correct 293 ms 78916 KB Output is correct
16 Correct 301 ms 78924 KB Output is correct
17 Correct 306 ms 79484 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 4 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 4 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 956 ms 81568 KB Output is correct
3 Correct 441 ms 78268 KB Output is correct
4 Correct 709 ms 82744 KB Output is correct
5 Correct 695 ms 79832 KB Output is correct
6 Correct 596 ms 80984 KB Output is correct
7 Correct 577 ms 80084 KB Output is correct
8 Correct 535 ms 80576 KB Output is correct
9 Correct 1022 ms 85632 KB Output is correct
10 Correct 419 ms 82252 KB Output is correct
11 Correct 970 ms 81416 KB Output is correct
12 Correct 396 ms 78396 KB Output is correct
13 Correct 292 ms 78852 KB Output is correct
14 Correct 299 ms 78836 KB Output is correct
15 Correct 293 ms 78916 KB Output is correct
16 Correct 301 ms 78924 KB Output is correct
17 Correct 306 ms 79484 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 4 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 4 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 962 ms 81500 KB Output is correct
25 Correct 405 ms 78284 KB Output is correct
26 Correct 710 ms 83956 KB Output is correct
27 Correct 673 ms 79936 KB Output is correct
28 Correct 597 ms 80100 KB Output is correct
29 Correct 573 ms 80100 KB Output is correct
30 Correct 537 ms 80756 KB Output is correct
31 Correct 987 ms 84364 KB Output is correct
32 Correct 415 ms 82380 KB Output is correct
33 Correct 945 ms 81612 KB Output is correct
34 Correct 413 ms 78208 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 4 ms 4948 KB Output is correct
37 Correct 4 ms 5076 KB Output is correct
38 Correct 3 ms 4972 KB Output is correct
39 Correct 4 ms 4948 KB Output is correct
40 Correct 3 ms 4948 KB Output is correct
41 Correct 4 ms 4948 KB Output is correct
42 Correct 4 ms 4948 KB Output is correct
43 Correct 3 ms 4948 KB Output is correct
44 Correct 4 ms 4948 KB Output is correct
45 Correct 5 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 4 ms 4948 KB Output is correct
48 Correct 4 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 1034 ms 83268 KB Output is correct
3 Correct 810 ms 81388 KB Output is correct
4 Correct 785 ms 81852 KB Output is correct
5 Correct 726 ms 78236 KB Output is correct
6 Correct 608 ms 78480 KB Output is correct
7 Correct 591 ms 78556 KB Output is correct
8 Correct 537 ms 79168 KB Output is correct
9 Correct 1004 ms 81844 KB Output is correct
10 Correct 757 ms 81840 KB Output is correct
11 Correct 1098 ms 78648 KB Output is correct
12 Correct 761 ms 78128 KB Output is correct
13 Correct 463 ms 78868 KB Output is correct
14 Correct 480 ms 79164 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 4 ms 4948 KB Output is correct
18 Correct 5 ms 4944 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5000 KB Output is correct
2 Correct 1259 ms 84268 KB Output is correct
3 Correct 812 ms 80468 KB Output is correct
4 Correct 869 ms 82272 KB Output is correct
5 Correct 812 ms 79868 KB Output is correct
6 Correct 681 ms 79976 KB Output is correct
7 Correct 646 ms 80040 KB Output is correct
8 Correct 591 ms 80376 KB Output is correct
9 Correct 1101 ms 85312 KB Output is correct
10 Correct 784 ms 82384 KB Output is correct
11 Correct 1079 ms 81392 KB Output is correct
12 Correct 685 ms 78348 KB Output is correct
13 Correct 460 ms 78956 KB Output is correct
14 Correct 505 ms 79400 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 5 ms 4948 KB Output is correct
17 Correct 4 ms 4948 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
# Verdict Execution time Memory 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 4 ms 5332 KB Output is correct
5 Correct 4 ms 5332 KB Output is correct
6 Correct 5 ms 5332 KB Output is correct
7 Correct 5 ms 5340 KB Output is correct
8 Correct 4 ms 5332 KB Output is correct
9 Correct 4 ms 5024 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 4 ms 5068 KB Output is correct
12 Correct 4 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 4 ms 4948 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 4944 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 4 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 4 ms 4948 KB Output is correct
26 Correct 4 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 956 ms 81568 KB Output is correct
31 Correct 441 ms 78268 KB Output is correct
32 Correct 709 ms 82744 KB Output is correct
33 Correct 695 ms 79832 KB Output is correct
34 Correct 596 ms 80984 KB Output is correct
35 Correct 577 ms 80084 KB Output is correct
36 Correct 535 ms 80576 KB Output is correct
37 Correct 1022 ms 85632 KB Output is correct
38 Correct 419 ms 82252 KB Output is correct
39 Correct 970 ms 81416 KB Output is correct
40 Correct 396 ms 78396 KB Output is correct
41 Correct 292 ms 78852 KB Output is correct
42 Correct 299 ms 78836 KB Output is correct
43 Correct 293 ms 78916 KB Output is correct
44 Correct 301 ms 78924 KB Output is correct
45 Correct 306 ms 79484 KB Output is correct
46 Correct 4 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 4 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 4 ms 4948 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 962 ms 81500 KB Output is correct
53 Correct 405 ms 78284 KB Output is correct
54 Correct 710 ms 83956 KB Output is correct
55 Correct 673 ms 79936 KB Output is correct
56 Correct 597 ms 80100 KB Output is correct
57 Correct 573 ms 80100 KB Output is correct
58 Correct 537 ms 80756 KB Output is correct
59 Correct 987 ms 84364 KB Output is correct
60 Correct 415 ms 82380 KB Output is correct
61 Correct 945 ms 81612 KB Output is correct
62 Correct 413 ms 78208 KB Output is correct
63 Correct 3 ms 4948 KB Output is correct
64 Correct 4 ms 4948 KB Output is correct
65 Correct 4 ms 5076 KB Output is correct
66 Correct 3 ms 4972 KB Output is correct
67 Correct 4 ms 4948 KB Output is correct
68 Correct 3 ms 4948 KB Output is correct
69 Correct 4 ms 4948 KB Output is correct
70 Correct 4 ms 4948 KB Output is correct
71 Correct 3 ms 4948 KB Output is correct
72 Correct 4 ms 4948 KB Output is correct
73 Correct 5 ms 4948 KB Output is correct
74 Correct 3 ms 4948 KB Output is correct
75 Correct 4 ms 4948 KB Output is correct
76 Correct 4 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 1034 ms 83268 KB Output is correct
80 Correct 810 ms 81388 KB Output is correct
81 Correct 785 ms 81852 KB Output is correct
82 Correct 726 ms 78236 KB Output is correct
83 Correct 608 ms 78480 KB Output is correct
84 Correct 591 ms 78556 KB Output is correct
85 Correct 537 ms 79168 KB Output is correct
86 Correct 1004 ms 81844 KB Output is correct
87 Correct 757 ms 81840 KB Output is correct
88 Correct 1098 ms 78648 KB Output is correct
89 Correct 761 ms 78128 KB Output is correct
90 Correct 463 ms 78868 KB Output is correct
91 Correct 480 ms 79164 KB Output is correct
92 Correct 3 ms 4948 KB Output is correct
93 Correct 4 ms 4948 KB Output is correct
94 Correct 4 ms 4948 KB Output is correct
95 Correct 5 ms 4944 KB Output is correct
96 Correct 3 ms 4948 KB Output is correct
97 Correct 3 ms 5000 KB Output is correct
98 Correct 1259 ms 84268 KB Output is correct
99 Correct 812 ms 80468 KB Output is correct
100 Correct 869 ms 82272 KB Output is correct
101 Correct 812 ms 79868 KB Output is correct
102 Correct 681 ms 79976 KB Output is correct
103 Correct 646 ms 80040 KB Output is correct
104 Correct 591 ms 80376 KB Output is correct
105 Correct 1101 ms 85312 KB Output is correct
106 Correct 784 ms 82384 KB Output is correct
107 Correct 1079 ms 81392 KB Output is correct
108 Correct 685 ms 78348 KB Output is correct
109 Correct 460 ms 78956 KB Output is correct
110 Correct 505 ms 79400 KB Output is correct
111 Correct 4 ms 4948 KB Output is correct
112 Correct 5 ms 4948 KB Output is correct
113 Correct 4 ms 4948 KB Output is correct
114 Correct 4 ms 4948 KB Output is correct
115 Correct 4 ms 4948 KB Output is correct
116 Correct 1000 ms 79516 KB Output is correct
117 Correct 675 ms 78024 KB Output is correct
118 Correct 813 ms 83852 KB Output is correct
119 Correct 777 ms 79752 KB Output is correct
120 Correct 663 ms 79784 KB Output is correct
121 Correct 671 ms 80196 KB Output is correct
122 Correct 608 ms 80500 KB Output is correct
123 Correct 1037 ms 84784 KB Output is correct
124 Correct 770 ms 80896 KB Output is correct
125 Correct 971 ms 80836 KB Output is correct
126 Correct 669 ms 78156 KB Output is correct
127 Correct 685 ms 78080 KB Output is correct
128 Correct 564 ms 78988 KB Output is correct
129 Correct 566 ms 79380 KB Output is correct