#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int N = 2e5 + 55;
const int K = 44;
int n, q, pr[N];
ll D[N][K], h[N], L;
vector < int > v[N];
void dfs(int x, int p) {
pr[x] = p;
for (int i = 0; i < v[x].size(); ++i) {
int to = v[x][i];
if (to == p) continue;
dfs(to, x);
}
}
main () {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> L;
for (int i = 1; i < n; ++i) {
int a, b;
cin >> a >> b;
v[a].pb(b);
v[b].pb(a);
}
dfs(1, 0);
int st = 0;
for (int i = n + 1; i <= n + 40; ++i) {
pr[st] = i;
st = i;
}
for (int i = 0; i <= n + 40; ++i) {
for (int j = 0; j <= 40; ++j) {
D[i][j] = 1;
}
}
for (int i = 1; i <= n; ++i) {
cin >> h[i];
}
cin >> q;
for (int i = 1; i <= q; ++i) {
int tp, x;
cin >> tp;
if (tp == 1) {
ll d, W;
cin >> x >> d >> W;
for (int j = d; j >= 0; --j) {
D[x][j] = (D[x][j] * W) % L;
if (0 < j) {
D[x][j - 1] = (D[x][j - 1] * W) % L;
}
D[x][j] %= L;
x = pr[x];
}
}
else
if (tp == 2) {
cin >> x;
ll ans = h[x];
for (int j = 0; j <= 40; ++j) {
ans = (ans * D[x][j]) % L;
x = pr[x];
}
cout << ans << "\n";
}
}
}
Compilation message
sprinkler.cpp: In function 'void dfs(int, int)':
sprinkler.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int i = 0; i < v[x].size(); ++i) {
| ~~^~~~~~~~~~~~~
sprinkler.cpp: At global scope:
sprinkler.cpp:24:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
24 | main () {
| ^~~~
# |
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 |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5460 KB |
Output is correct |
5 |
Correct |
4 ms |
5332 KB |
Output is correct |
6 |
Correct |
4 ms |
5332 KB |
Output is correct |
7 |
Correct |
3 ms |
5460 KB |
Output is correct |
8 |
Correct |
4 ms |
5332 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
9 ms |
4948 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 |
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 |
4 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 |
4 ms |
4948 KB |
Output is correct |
25 |
Correct |
4 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 |
4 ms |
5036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
617 ms |
89812 KB |
Output is correct |
3 |
Correct |
425 ms |
94852 KB |
Output is correct |
4 |
Correct |
563 ms |
100444 KB |
Output is correct |
5 |
Correct |
486 ms |
94648 KB |
Output is correct |
6 |
Correct |
383 ms |
94184 KB |
Output is correct |
7 |
Correct |
391 ms |
94812 KB |
Output is correct |
8 |
Correct |
301 ms |
95444 KB |
Output is correct |
9 |
Correct |
609 ms |
103176 KB |
Output is correct |
10 |
Correct |
369 ms |
103024 KB |
Output is correct |
11 |
Correct |
520 ms |
94332 KB |
Output is correct |
12 |
Correct |
338 ms |
94808 KB |
Output is correct |
13 |
Correct |
239 ms |
95112 KB |
Output is correct |
14 |
Correct |
258 ms |
95596 KB |
Output is correct |
15 |
Correct |
236 ms |
94972 KB |
Output is correct |
16 |
Correct |
280 ms |
95508 KB |
Output is correct |
17 |
Correct |
270 ms |
96012 KB |
Output is correct |
18 |
Correct |
3 ms |
5076 KB |
Output is correct |
19 |
Correct |
3 ms |
5076 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
617 ms |
89812 KB |
Output is correct |
3 |
Correct |
425 ms |
94852 KB |
Output is correct |
4 |
Correct |
563 ms |
100444 KB |
Output is correct |
5 |
Correct |
486 ms |
94648 KB |
Output is correct |
6 |
Correct |
383 ms |
94184 KB |
Output is correct |
7 |
Correct |
391 ms |
94812 KB |
Output is correct |
8 |
Correct |
301 ms |
95444 KB |
Output is correct |
9 |
Correct |
609 ms |
103176 KB |
Output is correct |
10 |
Correct |
369 ms |
103024 KB |
Output is correct |
11 |
Correct |
520 ms |
94332 KB |
Output is correct |
12 |
Correct |
338 ms |
94808 KB |
Output is correct |
13 |
Correct |
239 ms |
95112 KB |
Output is correct |
14 |
Correct |
258 ms |
95596 KB |
Output is correct |
15 |
Correct |
236 ms |
94972 KB |
Output is correct |
16 |
Correct |
280 ms |
95508 KB |
Output is correct |
17 |
Correct |
270 ms |
96012 KB |
Output is correct |
18 |
Correct |
3 ms |
5076 KB |
Output is correct |
19 |
Correct |
3 ms |
5076 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
4 ms |
4948 KB |
Output is correct |
24 |
Correct |
489 ms |
94404 KB |
Output is correct |
25 |
Correct |
354 ms |
94952 KB |
Output is correct |
26 |
Correct |
462 ms |
103276 KB |
Output is correct |
27 |
Correct |
446 ms |
94548 KB |
Output is correct |
28 |
Correct |
356 ms |
94704 KB |
Output is correct |
29 |
Correct |
347 ms |
94396 KB |
Output is correct |
30 |
Correct |
296 ms |
95468 KB |
Output is correct |
31 |
Correct |
513 ms |
100556 KB |
Output is correct |
32 |
Correct |
385 ms |
103112 KB |
Output is correct |
33 |
Correct |
576 ms |
94400 KB |
Output is correct |
34 |
Correct |
342 ms |
94832 KB |
Output is correct |
35 |
Correct |
3 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
5076 KB |
Output is correct |
37 |
Correct |
3 ms |
5076 KB |
Output is correct |
38 |
Correct |
3 ms |
5044 KB |
Output is correct |
39 |
Correct |
3 ms |
5076 KB |
Output is correct |
40 |
Correct |
3 ms |
4948 KB |
Output is correct |
41 |
Correct |
3 ms |
5068 KB |
Output is correct |
42 |
Correct |
3 ms |
4948 KB |
Output is correct |
43 |
Correct |
3 ms |
5036 KB |
Output is correct |
44 |
Correct |
4 ms |
4948 KB |
Output is correct |
45 |
Correct |
3 ms |
4948 KB |
Output is correct |
46 |
Correct |
3 ms |
5076 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
569 ms |
95608 KB |
Output is correct |
3 |
Correct |
717 ms |
98892 KB |
Output is correct |
4 |
Correct |
540 ms |
98796 KB |
Output is correct |
5 |
Correct |
588 ms |
91640 KB |
Output is correct |
6 |
Correct |
443 ms |
91700 KB |
Output is correct |
7 |
Correct |
356 ms |
91932 KB |
Output is correct |
8 |
Correct |
346 ms |
92508 KB |
Output is correct |
9 |
Correct |
556 ms |
97736 KB |
Output is correct |
10 |
Correct |
745 ms |
100100 KB |
Output is correct |
11 |
Correct |
540 ms |
91276 KB |
Output is correct |
12 |
Correct |
631 ms |
92232 KB |
Output is correct |
13 |
Correct |
445 ms |
93036 KB |
Output is correct |
14 |
Correct |
458 ms |
93592 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
5036 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
5008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
581 ms |
95360 KB |
Output is correct |
3 |
Correct |
738 ms |
97116 KB |
Output is correct |
4 |
Correct |
565 ms |
98512 KB |
Output is correct |
5 |
Correct |
491 ms |
93228 KB |
Output is correct |
6 |
Correct |
397 ms |
93280 KB |
Output is correct |
7 |
Correct |
448 ms |
93144 KB |
Output is correct |
8 |
Correct |
334 ms |
93376 KB |
Output is correct |
9 |
Correct |
601 ms |
102308 KB |
Output is correct |
10 |
Correct |
731 ms |
100956 KB |
Output is correct |
11 |
Correct |
528 ms |
94036 KB |
Output is correct |
12 |
Correct |
613 ms |
92536 KB |
Output is correct |
13 |
Correct |
440 ms |
93200 KB |
Output is correct |
14 |
Correct |
515 ms |
93764 KB |
Output is correct |
15 |
Correct |
4 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 |
3 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 |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5460 KB |
Output is correct |
5 |
Correct |
4 ms |
5332 KB |
Output is correct |
6 |
Correct |
4 ms |
5332 KB |
Output is correct |
7 |
Correct |
3 ms |
5460 KB |
Output is correct |
8 |
Correct |
4 ms |
5332 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
9 ms |
4948 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 |
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 |
4 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 |
4 ms |
4948 KB |
Output is correct |
25 |
Correct |
4 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 |
4 ms |
5036 KB |
Output is correct |
29 |
Correct |
3 ms |
4948 KB |
Output is correct |
30 |
Correct |
617 ms |
89812 KB |
Output is correct |
31 |
Correct |
425 ms |
94852 KB |
Output is correct |
32 |
Correct |
563 ms |
100444 KB |
Output is correct |
33 |
Correct |
486 ms |
94648 KB |
Output is correct |
34 |
Correct |
383 ms |
94184 KB |
Output is correct |
35 |
Correct |
391 ms |
94812 KB |
Output is correct |
36 |
Correct |
301 ms |
95444 KB |
Output is correct |
37 |
Correct |
609 ms |
103176 KB |
Output is correct |
38 |
Correct |
369 ms |
103024 KB |
Output is correct |
39 |
Correct |
520 ms |
94332 KB |
Output is correct |
40 |
Correct |
338 ms |
94808 KB |
Output is correct |
41 |
Correct |
239 ms |
95112 KB |
Output is correct |
42 |
Correct |
258 ms |
95596 KB |
Output is correct |
43 |
Correct |
236 ms |
94972 KB |
Output is correct |
44 |
Correct |
280 ms |
95508 KB |
Output is correct |
45 |
Correct |
270 ms |
96012 KB |
Output is correct |
46 |
Correct |
3 ms |
5076 KB |
Output is correct |
47 |
Correct |
3 ms |
5076 KB |
Output is correct |
48 |
Correct |
3 ms |
5076 KB |
Output is correct |
49 |
Correct |
3 ms |
4948 KB |
Output is correct |
50 |
Correct |
3 ms |
5076 KB |
Output is correct |
51 |
Correct |
4 ms |
4948 KB |
Output is correct |
52 |
Correct |
489 ms |
94404 KB |
Output is correct |
53 |
Correct |
354 ms |
94952 KB |
Output is correct |
54 |
Correct |
462 ms |
103276 KB |
Output is correct |
55 |
Correct |
446 ms |
94548 KB |
Output is correct |
56 |
Correct |
356 ms |
94704 KB |
Output is correct |
57 |
Correct |
347 ms |
94396 KB |
Output is correct |
58 |
Correct |
296 ms |
95468 KB |
Output is correct |
59 |
Correct |
513 ms |
100556 KB |
Output is correct |
60 |
Correct |
385 ms |
103112 KB |
Output is correct |
61 |
Correct |
576 ms |
94400 KB |
Output is correct |
62 |
Correct |
342 ms |
94832 KB |
Output is correct |
63 |
Correct |
3 ms |
4948 KB |
Output is correct |
64 |
Correct |
3 ms |
5076 KB |
Output is correct |
65 |
Correct |
3 ms |
5076 KB |
Output is correct |
66 |
Correct |
3 ms |
5044 KB |
Output is correct |
67 |
Correct |
3 ms |
5076 KB |
Output is correct |
68 |
Correct |
3 ms |
4948 KB |
Output is correct |
69 |
Correct |
3 ms |
5068 KB |
Output is correct |
70 |
Correct |
3 ms |
4948 KB |
Output is correct |
71 |
Correct |
3 ms |
5036 KB |
Output is correct |
72 |
Correct |
4 ms |
4948 KB |
Output is correct |
73 |
Correct |
3 ms |
4948 KB |
Output is correct |
74 |
Correct |
3 ms |
5076 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 |
569 ms |
95608 KB |
Output is correct |
80 |
Correct |
717 ms |
98892 KB |
Output is correct |
81 |
Correct |
540 ms |
98796 KB |
Output is correct |
82 |
Correct |
588 ms |
91640 KB |
Output is correct |
83 |
Correct |
443 ms |
91700 KB |
Output is correct |
84 |
Correct |
356 ms |
91932 KB |
Output is correct |
85 |
Correct |
346 ms |
92508 KB |
Output is correct |
86 |
Correct |
556 ms |
97736 KB |
Output is correct |
87 |
Correct |
745 ms |
100100 KB |
Output is correct |
88 |
Correct |
540 ms |
91276 KB |
Output is correct |
89 |
Correct |
631 ms |
92232 KB |
Output is correct |
90 |
Correct |
445 ms |
93036 KB |
Output is correct |
91 |
Correct |
458 ms |
93592 KB |
Output is correct |
92 |
Correct |
3 ms |
4948 KB |
Output is correct |
93 |
Correct |
3 ms |
5036 KB |
Output is correct |
94 |
Correct |
3 ms |
4948 KB |
Output is correct |
95 |
Correct |
4 ms |
4948 KB |
Output is correct |
96 |
Correct |
4 ms |
5008 KB |
Output is correct |
97 |
Correct |
3 ms |
4948 KB |
Output is correct |
98 |
Correct |
581 ms |
95360 KB |
Output is correct |
99 |
Correct |
738 ms |
97116 KB |
Output is correct |
100 |
Correct |
565 ms |
98512 KB |
Output is correct |
101 |
Correct |
491 ms |
93228 KB |
Output is correct |
102 |
Correct |
397 ms |
93280 KB |
Output is correct |
103 |
Correct |
448 ms |
93144 KB |
Output is correct |
104 |
Correct |
334 ms |
93376 KB |
Output is correct |
105 |
Correct |
601 ms |
102308 KB |
Output is correct |
106 |
Correct |
731 ms |
100956 KB |
Output is correct |
107 |
Correct |
528 ms |
94036 KB |
Output is correct |
108 |
Correct |
613 ms |
92536 KB |
Output is correct |
109 |
Correct |
440 ms |
93200 KB |
Output is correct |
110 |
Correct |
515 ms |
93764 KB |
Output is correct |
111 |
Correct |
4 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 |
3 ms |
4948 KB |
Output is correct |
115 |
Correct |
4 ms |
4948 KB |
Output is correct |
116 |
Correct |
530 ms |
92424 KB |
Output is correct |
117 |
Correct |
642 ms |
95108 KB |
Output is correct |
118 |
Correct |
568 ms |
103096 KB |
Output is correct |
119 |
Correct |
539 ms |
94672 KB |
Output is correct |
120 |
Correct |
475 ms |
94184 KB |
Output is correct |
121 |
Correct |
485 ms |
95016 KB |
Output is correct |
122 |
Correct |
392 ms |
95372 KB |
Output is correct |
123 |
Correct |
586 ms |
101480 KB |
Output is correct |
124 |
Correct |
789 ms |
100220 KB |
Output is correct |
125 |
Correct |
565 ms |
93524 KB |
Output is correct |
126 |
Correct |
657 ms |
94984 KB |
Output is correct |
127 |
Correct |
720 ms |
95392 KB |
Output is correct |
128 |
Correct |
577 ms |
95944 KB |
Output is correct |
129 |
Correct |
593 ms |
96468 KB |
Output is correct |