#include <bits/stdc++.h>
using namespace std;
int N, L;
struct st
{
vector<long long>r;
int treeN;
void init(int cnt)
{
for (treeN = 1; treeN < cnt; treeN *= 2);
r.resize(2 * treeN + 3, 1);
}
void upd(int qs, int qe, int n, int s, int e, int i = 1)
{
if (s > qe || qs > e)
return;
if (qs <= s && e <= qe)
{
r[i] *= n;
r[i] %= L;
return;
}
upd(qs, qe, n, s, (s + e) / 2, i * 2);
upd(qs, qe, n, (s + e) / 2 + 1, e, i * 2 + 1);
}
int ge(int qs, int qe, int n, int i = 1)
{
if (qs == qe)
{
return r[i];
}
int m = (qs + qe) / 2;
if (n > m)
{
return r[i] * ge(m + 1, qe, n, i * 2 + 1) % L;
}
else
{
return r[i] * ge(qs, m, n, i * 2) % L;
}
}
}arr[200100];
int d[201000];
int pos[200100];
int par[200100];
int st[201000];
int en[200100];
int sp[200100][50], ep[200100][50];
int c;
vector<int>li[201000];
vector<pair<int, int>>dl[200100];
void dfs(int n, int p = 0)
{
st[n] = ++c;
dl[d[n]].push_back({ st[n],n });
sp[n][0] = ep[n][0] = dl[d[n]].size() - 1;
int i;
for (i = 0; i < li[n].size(); i++)
{
if (li[n][i] == p)
continue;
par[li[n][i]] = n;
d[li[n][i]] = d[n] + 1;
dfs(li[n][i], n);
int j;
for (j = 1; j < 43; j++)
{
sp[n][j] = min(sp[n][j], sp[li[n][i]][j - 1]);
ep[n][j] = max(ep[n][j], ep[li[n][i]][j - 1]);
}
}
en[n] = c;
}
signed main()
{
memset(sp, 10, sizeof(sp));
memset(ep, -10, sizeof(ep));
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> L;
int i;
for (i = 1; i < N; i++)
{
int a, b;
cin >> a >> b;
li[a].push_back(b);
li[b].push_back(a);
}
dfs(1);
for (i = 0; i <= N; i++)
{
arr[i].init(dl[i].size());
int j;
for (j = 0; j < dl[i].size(); j++)
{
pos[dl[i][j].second] = j;
}
}
for (i = 1; i <= N; i++)
{
int a;
cin >> a;
arr[d[i]].r[pos[i] + arr[d[i]].treeN] = a;
}
int Q;
cin >> Q;
while (Q--)
{
int a;
cin >> a;
if (a == 1)
{
int b, c, w;
cin >> b >> c >> w;
int j;
int dp = d[b];
int cp = b;
for (j = dp + c; j >= dp - c; j--)
{
if (j + dp - d[cp] * 2 + 2 <= c && cp != 1)
{
cp = par[cp];
}
if (j < 0)
break;
int lp = sp[cp][j - d[cp]];
int rp = ep[cp][j - d[cp]];
if (lp <= rp)
{
arr[j].upd(lp, rp, w, 0, arr[j].treeN - 1);
}
}
}
else
{
int b;
cin >> b;
cout << arr[d[b]].ge(0, arr[d[b]].treeN - 1, pos[b]) << '\n';
}
}
}
Compilation message
sprinkler.cpp: In function 'void dfs(int, int)':
sprinkler.cpp:59:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (i = 0; i < li[n].size(); i++)
| ~~^~~~~~~~~~~~~~
sprinkler.cpp: In function 'int main()':
sprinkler.cpp:95:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for (j = 0; j < dl[i].size(); j++)
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
94284 KB |
Output is correct |
2 |
Correct |
38 ms |
94284 KB |
Output is correct |
3 |
Correct |
38 ms |
94260 KB |
Output is correct |
4 |
Correct |
39 ms |
94536 KB |
Output is correct |
5 |
Correct |
38 ms |
94480 KB |
Output is correct |
6 |
Correct |
41 ms |
94476 KB |
Output is correct |
7 |
Correct |
41 ms |
94460 KB |
Output is correct |
8 |
Correct |
49 ms |
94452 KB |
Output is correct |
9 |
Correct |
38 ms |
94316 KB |
Output is correct |
10 |
Correct |
38 ms |
94284 KB |
Output is correct |
11 |
Correct |
37 ms |
94332 KB |
Output is correct |
12 |
Correct |
37 ms |
94288 KB |
Output is correct |
13 |
Correct |
38 ms |
94232 KB |
Output is correct |
14 |
Correct |
37 ms |
94308 KB |
Output is correct |
15 |
Correct |
45 ms |
94344 KB |
Output is correct |
16 |
Correct |
47 ms |
94252 KB |
Output is correct |
17 |
Correct |
41 ms |
94252 KB |
Output is correct |
18 |
Correct |
37 ms |
94268 KB |
Output is correct |
19 |
Correct |
38 ms |
94224 KB |
Output is correct |
20 |
Correct |
38 ms |
94316 KB |
Output is correct |
21 |
Correct |
38 ms |
94224 KB |
Output is correct |
22 |
Correct |
40 ms |
94336 KB |
Output is correct |
23 |
Correct |
47 ms |
94344 KB |
Output is correct |
24 |
Correct |
46 ms |
94312 KB |
Output is correct |
25 |
Correct |
37 ms |
94364 KB |
Output is correct |
26 |
Correct |
37 ms |
94288 KB |
Output is correct |
27 |
Correct |
37 ms |
94244 KB |
Output is correct |
28 |
Correct |
42 ms |
94280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
94284 KB |
Output is correct |
2 |
Correct |
492 ms |
128576 KB |
Output is correct |
3 |
Correct |
641 ms |
128404 KB |
Output is correct |
4 |
Correct |
654 ms |
138728 KB |
Output is correct |
5 |
Correct |
538 ms |
126760 KB |
Output is correct |
6 |
Correct |
611 ms |
126040 KB |
Output is correct |
7 |
Correct |
578 ms |
125964 KB |
Output is correct |
8 |
Correct |
464 ms |
125868 KB |
Output is correct |
9 |
Correct |
555 ms |
148528 KB |
Output is correct |
10 |
Correct |
623 ms |
144096 KB |
Output is correct |
11 |
Correct |
465 ms |
127984 KB |
Output is correct |
12 |
Correct |
612 ms |
125696 KB |
Output is correct |
13 |
Correct |
407 ms |
128308 KB |
Output is correct |
14 |
Correct |
478 ms |
128912 KB |
Output is correct |
15 |
Correct |
506 ms |
128408 KB |
Output is correct |
16 |
Correct |
508 ms |
128360 KB |
Output is correct |
17 |
Correct |
523 ms |
128492 KB |
Output is correct |
18 |
Correct |
39 ms |
94292 KB |
Output is correct |
19 |
Correct |
47 ms |
94280 KB |
Output is correct |
20 |
Correct |
38 ms |
94292 KB |
Output is correct |
21 |
Correct |
41 ms |
94320 KB |
Output is correct |
22 |
Correct |
42 ms |
94328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
94284 KB |
Output is correct |
2 |
Correct |
492 ms |
128576 KB |
Output is correct |
3 |
Correct |
641 ms |
128404 KB |
Output is correct |
4 |
Correct |
654 ms |
138728 KB |
Output is correct |
5 |
Correct |
538 ms |
126760 KB |
Output is correct |
6 |
Correct |
611 ms |
126040 KB |
Output is correct |
7 |
Correct |
578 ms |
125964 KB |
Output is correct |
8 |
Correct |
464 ms |
125868 KB |
Output is correct |
9 |
Correct |
555 ms |
148528 KB |
Output is correct |
10 |
Correct |
623 ms |
144096 KB |
Output is correct |
11 |
Correct |
465 ms |
127984 KB |
Output is correct |
12 |
Correct |
612 ms |
125696 KB |
Output is correct |
13 |
Correct |
407 ms |
128308 KB |
Output is correct |
14 |
Correct |
478 ms |
128912 KB |
Output is correct |
15 |
Correct |
506 ms |
128408 KB |
Output is correct |
16 |
Correct |
508 ms |
128360 KB |
Output is correct |
17 |
Correct |
523 ms |
128492 KB |
Output is correct |
18 |
Correct |
39 ms |
94292 KB |
Output is correct |
19 |
Correct |
47 ms |
94280 KB |
Output is correct |
20 |
Correct |
38 ms |
94292 KB |
Output is correct |
21 |
Correct |
41 ms |
94320 KB |
Output is correct |
22 |
Correct |
42 ms |
94328 KB |
Output is correct |
23 |
Correct |
39 ms |
94292 KB |
Output is correct |
24 |
Correct |
484 ms |
128568 KB |
Output is correct |
25 |
Correct |
816 ms |
125884 KB |
Output is correct |
26 |
Correct |
621 ms |
146704 KB |
Output is correct |
27 |
Correct |
594 ms |
127312 KB |
Output is correct |
28 |
Correct |
638 ms |
127016 KB |
Output is correct |
29 |
Correct |
646 ms |
127212 KB |
Output is correct |
30 |
Correct |
495 ms |
126764 KB |
Output is correct |
31 |
Correct |
555 ms |
141924 KB |
Output is correct |
32 |
Correct |
633 ms |
144328 KB |
Output is correct |
33 |
Correct |
505 ms |
128900 KB |
Output is correct |
34 |
Correct |
772 ms |
125708 KB |
Output is correct |
35 |
Correct |
37 ms |
94332 KB |
Output is correct |
36 |
Correct |
44 ms |
94360 KB |
Output is correct |
37 |
Correct |
40 ms |
94284 KB |
Output is correct |
38 |
Correct |
38 ms |
94356 KB |
Output is correct |
39 |
Correct |
39 ms |
94284 KB |
Output is correct |
40 |
Correct |
39 ms |
94284 KB |
Output is correct |
41 |
Correct |
41 ms |
94256 KB |
Output is correct |
42 |
Correct |
38 ms |
94260 KB |
Output is correct |
43 |
Correct |
44 ms |
94280 KB |
Output is correct |
44 |
Correct |
37 ms |
94264 KB |
Output is correct |
45 |
Correct |
37 ms |
94340 KB |
Output is correct |
46 |
Correct |
37 ms |
94252 KB |
Output is correct |
47 |
Correct |
41 ms |
94280 KB |
Output is correct |
48 |
Correct |
39 ms |
94324 KB |
Output is correct |
49 |
Correct |
38 ms |
94416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
94300 KB |
Output is correct |
2 |
Correct |
689 ms |
141804 KB |
Output is correct |
3 |
Correct |
2794 ms |
135176 KB |
Output is correct |
4 |
Correct |
1154 ms |
136692 KB |
Output is correct |
5 |
Correct |
1732 ms |
121104 KB |
Output is correct |
6 |
Correct |
1268 ms |
120700 KB |
Output is correct |
7 |
Correct |
851 ms |
121520 KB |
Output is correct |
8 |
Correct |
419 ms |
120760 KB |
Output is correct |
9 |
Correct |
787 ms |
134864 KB |
Output is correct |
10 |
Correct |
2473 ms |
139144 KB |
Output is correct |
11 |
Correct |
989 ms |
121760 KB |
Output is correct |
12 |
Execution timed out |
4097 ms |
120964 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
94292 KB |
Output is correct |
2 |
Correct |
915 ms |
136408 KB |
Output is correct |
3 |
Correct |
3413 ms |
130040 KB |
Output is correct |
4 |
Correct |
1324 ms |
133728 KB |
Output is correct |
5 |
Correct |
1780 ms |
123028 KB |
Output is correct |
6 |
Correct |
1101 ms |
122900 KB |
Output is correct |
7 |
Correct |
897 ms |
121796 KB |
Output is correct |
8 |
Correct |
412 ms |
122064 KB |
Output is correct |
9 |
Correct |
762 ms |
143048 KB |
Output is correct |
10 |
Correct |
2519 ms |
140184 KB |
Output is correct |
11 |
Correct |
1057 ms |
124120 KB |
Output is correct |
12 |
Execution timed out |
4043 ms |
121720 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
94284 KB |
Output is correct |
2 |
Correct |
38 ms |
94284 KB |
Output is correct |
3 |
Correct |
38 ms |
94260 KB |
Output is correct |
4 |
Correct |
39 ms |
94536 KB |
Output is correct |
5 |
Correct |
38 ms |
94480 KB |
Output is correct |
6 |
Correct |
41 ms |
94476 KB |
Output is correct |
7 |
Correct |
41 ms |
94460 KB |
Output is correct |
8 |
Correct |
49 ms |
94452 KB |
Output is correct |
9 |
Correct |
38 ms |
94316 KB |
Output is correct |
10 |
Correct |
38 ms |
94284 KB |
Output is correct |
11 |
Correct |
37 ms |
94332 KB |
Output is correct |
12 |
Correct |
37 ms |
94288 KB |
Output is correct |
13 |
Correct |
38 ms |
94232 KB |
Output is correct |
14 |
Correct |
37 ms |
94308 KB |
Output is correct |
15 |
Correct |
45 ms |
94344 KB |
Output is correct |
16 |
Correct |
47 ms |
94252 KB |
Output is correct |
17 |
Correct |
41 ms |
94252 KB |
Output is correct |
18 |
Correct |
37 ms |
94268 KB |
Output is correct |
19 |
Correct |
38 ms |
94224 KB |
Output is correct |
20 |
Correct |
38 ms |
94316 KB |
Output is correct |
21 |
Correct |
38 ms |
94224 KB |
Output is correct |
22 |
Correct |
40 ms |
94336 KB |
Output is correct |
23 |
Correct |
47 ms |
94344 KB |
Output is correct |
24 |
Correct |
46 ms |
94312 KB |
Output is correct |
25 |
Correct |
37 ms |
94364 KB |
Output is correct |
26 |
Correct |
37 ms |
94288 KB |
Output is correct |
27 |
Correct |
37 ms |
94244 KB |
Output is correct |
28 |
Correct |
42 ms |
94280 KB |
Output is correct |
29 |
Correct |
44 ms |
94284 KB |
Output is correct |
30 |
Correct |
492 ms |
128576 KB |
Output is correct |
31 |
Correct |
641 ms |
128404 KB |
Output is correct |
32 |
Correct |
654 ms |
138728 KB |
Output is correct |
33 |
Correct |
538 ms |
126760 KB |
Output is correct |
34 |
Correct |
611 ms |
126040 KB |
Output is correct |
35 |
Correct |
578 ms |
125964 KB |
Output is correct |
36 |
Correct |
464 ms |
125868 KB |
Output is correct |
37 |
Correct |
555 ms |
148528 KB |
Output is correct |
38 |
Correct |
623 ms |
144096 KB |
Output is correct |
39 |
Correct |
465 ms |
127984 KB |
Output is correct |
40 |
Correct |
612 ms |
125696 KB |
Output is correct |
41 |
Correct |
407 ms |
128308 KB |
Output is correct |
42 |
Correct |
478 ms |
128912 KB |
Output is correct |
43 |
Correct |
506 ms |
128408 KB |
Output is correct |
44 |
Correct |
508 ms |
128360 KB |
Output is correct |
45 |
Correct |
523 ms |
128492 KB |
Output is correct |
46 |
Correct |
39 ms |
94292 KB |
Output is correct |
47 |
Correct |
47 ms |
94280 KB |
Output is correct |
48 |
Correct |
38 ms |
94292 KB |
Output is correct |
49 |
Correct |
41 ms |
94320 KB |
Output is correct |
50 |
Correct |
42 ms |
94328 KB |
Output is correct |
51 |
Correct |
39 ms |
94292 KB |
Output is correct |
52 |
Correct |
484 ms |
128568 KB |
Output is correct |
53 |
Correct |
816 ms |
125884 KB |
Output is correct |
54 |
Correct |
621 ms |
146704 KB |
Output is correct |
55 |
Correct |
594 ms |
127312 KB |
Output is correct |
56 |
Correct |
638 ms |
127016 KB |
Output is correct |
57 |
Correct |
646 ms |
127212 KB |
Output is correct |
58 |
Correct |
495 ms |
126764 KB |
Output is correct |
59 |
Correct |
555 ms |
141924 KB |
Output is correct |
60 |
Correct |
633 ms |
144328 KB |
Output is correct |
61 |
Correct |
505 ms |
128900 KB |
Output is correct |
62 |
Correct |
772 ms |
125708 KB |
Output is correct |
63 |
Correct |
37 ms |
94332 KB |
Output is correct |
64 |
Correct |
44 ms |
94360 KB |
Output is correct |
65 |
Correct |
40 ms |
94284 KB |
Output is correct |
66 |
Correct |
38 ms |
94356 KB |
Output is correct |
67 |
Correct |
39 ms |
94284 KB |
Output is correct |
68 |
Correct |
39 ms |
94284 KB |
Output is correct |
69 |
Correct |
41 ms |
94256 KB |
Output is correct |
70 |
Correct |
38 ms |
94260 KB |
Output is correct |
71 |
Correct |
44 ms |
94280 KB |
Output is correct |
72 |
Correct |
37 ms |
94264 KB |
Output is correct |
73 |
Correct |
37 ms |
94340 KB |
Output is correct |
74 |
Correct |
37 ms |
94252 KB |
Output is correct |
75 |
Correct |
41 ms |
94280 KB |
Output is correct |
76 |
Correct |
39 ms |
94324 KB |
Output is correct |
77 |
Correct |
38 ms |
94416 KB |
Output is correct |
78 |
Correct |
38 ms |
94300 KB |
Output is correct |
79 |
Correct |
689 ms |
141804 KB |
Output is correct |
80 |
Correct |
2794 ms |
135176 KB |
Output is correct |
81 |
Correct |
1154 ms |
136692 KB |
Output is correct |
82 |
Correct |
1732 ms |
121104 KB |
Output is correct |
83 |
Correct |
1268 ms |
120700 KB |
Output is correct |
84 |
Correct |
851 ms |
121520 KB |
Output is correct |
85 |
Correct |
419 ms |
120760 KB |
Output is correct |
86 |
Correct |
787 ms |
134864 KB |
Output is correct |
87 |
Correct |
2473 ms |
139144 KB |
Output is correct |
88 |
Correct |
989 ms |
121760 KB |
Output is correct |
89 |
Execution timed out |
4097 ms |
120964 KB |
Time limit exceeded |
90 |
Halted |
0 ms |
0 KB |
- |