#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);
}
long long 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][100],ep[200100][100];
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 < 90; 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 |
76 ms |
172524 KB |
Output is correct |
2 |
Correct |
74 ms |
172560 KB |
Output is correct |
3 |
Correct |
79 ms |
172644 KB |
Output is correct |
4 |
Correct |
95 ms |
172816 KB |
Output is correct |
5 |
Correct |
69 ms |
172728 KB |
Output is correct |
6 |
Correct |
89 ms |
172836 KB |
Output is correct |
7 |
Correct |
88 ms |
172700 KB |
Output is correct |
8 |
Correct |
88 ms |
172708 KB |
Output is correct |
9 |
Correct |
76 ms |
172544 KB |
Output is correct |
10 |
Correct |
70 ms |
172608 KB |
Output is correct |
11 |
Correct |
72 ms |
172568 KB |
Output is correct |
12 |
Correct |
70 ms |
172636 KB |
Output is correct |
13 |
Correct |
83 ms |
172652 KB |
Output is correct |
14 |
Correct |
83 ms |
172548 KB |
Output is correct |
15 |
Correct |
76 ms |
172624 KB |
Output is correct |
16 |
Correct |
82 ms |
172624 KB |
Output is correct |
17 |
Correct |
73 ms |
172628 KB |
Output is correct |
18 |
Correct |
75 ms |
172592 KB |
Output is correct |
19 |
Correct |
75 ms |
172612 KB |
Output is correct |
20 |
Correct |
83 ms |
172700 KB |
Output is correct |
21 |
Correct |
86 ms |
172536 KB |
Output is correct |
22 |
Correct |
72 ms |
172524 KB |
Output is correct |
23 |
Correct |
69 ms |
172536 KB |
Output is correct |
24 |
Correct |
74 ms |
172564 KB |
Output is correct |
25 |
Correct |
67 ms |
172544 KB |
Output is correct |
26 |
Correct |
81 ms |
172592 KB |
Output is correct |
27 |
Correct |
69 ms |
172616 KB |
Output is correct |
28 |
Correct |
77 ms |
172532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
172664 KB |
Output is correct |
2 |
Correct |
502 ms |
202836 KB |
Output is correct |
3 |
Correct |
718 ms |
199712 KB |
Output is correct |
4 |
Correct |
673 ms |
213376 KB |
Output is correct |
5 |
Correct |
615 ms |
201292 KB |
Output is correct |
6 |
Correct |
589 ms |
200716 KB |
Output is correct |
7 |
Correct |
618 ms |
200540 KB |
Output is correct |
8 |
Correct |
501 ms |
200628 KB |
Output is correct |
9 |
Correct |
557 ms |
223264 KB |
Output is correct |
10 |
Correct |
660 ms |
218028 KB |
Output is correct |
11 |
Correct |
626 ms |
202644 KB |
Output is correct |
12 |
Correct |
653 ms |
199696 KB |
Output is correct |
13 |
Correct |
459 ms |
199536 KB |
Output is correct |
14 |
Correct |
521 ms |
200204 KB |
Output is correct |
15 |
Correct |
504 ms |
199804 KB |
Output is correct |
16 |
Correct |
546 ms |
199832 KB |
Output is correct |
17 |
Correct |
554 ms |
199684 KB |
Output is correct |
18 |
Correct |
82 ms |
172588 KB |
Output is correct |
19 |
Correct |
73 ms |
172592 KB |
Output is correct |
20 |
Correct |
67 ms |
172576 KB |
Output is correct |
21 |
Correct |
70 ms |
172584 KB |
Output is correct |
22 |
Correct |
68 ms |
172616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
172664 KB |
Output is correct |
2 |
Correct |
502 ms |
202836 KB |
Output is correct |
3 |
Correct |
718 ms |
199712 KB |
Output is correct |
4 |
Correct |
673 ms |
213376 KB |
Output is correct |
5 |
Correct |
615 ms |
201292 KB |
Output is correct |
6 |
Correct |
589 ms |
200716 KB |
Output is correct |
7 |
Correct |
618 ms |
200540 KB |
Output is correct |
8 |
Correct |
501 ms |
200628 KB |
Output is correct |
9 |
Correct |
557 ms |
223264 KB |
Output is correct |
10 |
Correct |
660 ms |
218028 KB |
Output is correct |
11 |
Correct |
626 ms |
202644 KB |
Output is correct |
12 |
Correct |
653 ms |
199696 KB |
Output is correct |
13 |
Correct |
459 ms |
199536 KB |
Output is correct |
14 |
Correct |
521 ms |
200204 KB |
Output is correct |
15 |
Correct |
504 ms |
199804 KB |
Output is correct |
16 |
Correct |
546 ms |
199832 KB |
Output is correct |
17 |
Correct |
554 ms |
199684 KB |
Output is correct |
18 |
Correct |
82 ms |
172588 KB |
Output is correct |
19 |
Correct |
73 ms |
172592 KB |
Output is correct |
20 |
Correct |
67 ms |
172576 KB |
Output is correct |
21 |
Correct |
70 ms |
172584 KB |
Output is correct |
22 |
Correct |
68 ms |
172616 KB |
Output is correct |
23 |
Correct |
66 ms |
172648 KB |
Output is correct |
24 |
Correct |
618 ms |
202596 KB |
Output is correct |
25 |
Correct |
847 ms |
199864 KB |
Output is correct |
26 |
Correct |
612 ms |
220512 KB |
Output is correct |
27 |
Correct |
616 ms |
201112 KB |
Output is correct |
28 |
Correct |
702 ms |
200816 KB |
Output is correct |
29 |
Correct |
616 ms |
201064 KB |
Output is correct |
30 |
Correct |
511 ms |
200760 KB |
Output is correct |
31 |
Correct |
592 ms |
215728 KB |
Output is correct |
32 |
Correct |
765 ms |
218080 KB |
Output is correct |
33 |
Correct |
580 ms |
202656 KB |
Output is correct |
34 |
Correct |
845 ms |
199288 KB |
Output is correct |
35 |
Correct |
68 ms |
172620 KB |
Output is correct |
36 |
Correct |
67 ms |
172576 KB |
Output is correct |
37 |
Correct |
70 ms |
172568 KB |
Output is correct |
38 |
Correct |
84 ms |
172604 KB |
Output is correct |
39 |
Correct |
72 ms |
172556 KB |
Output is correct |
40 |
Correct |
76 ms |
172600 KB |
Output is correct |
41 |
Correct |
68 ms |
172580 KB |
Output is correct |
42 |
Correct |
66 ms |
172536 KB |
Output is correct |
43 |
Correct |
66 ms |
172604 KB |
Output is correct |
44 |
Correct |
85 ms |
172648 KB |
Output is correct |
45 |
Correct |
67 ms |
172584 KB |
Output is correct |
46 |
Correct |
73 ms |
172552 KB |
Output is correct |
47 |
Correct |
67 ms |
172620 KB |
Output is correct |
48 |
Correct |
67 ms |
172596 KB |
Output is correct |
49 |
Correct |
71 ms |
172688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
172636 KB |
Output is correct |
2 |
Correct |
749 ms |
220116 KB |
Output is correct |
3 |
Correct |
3326 ms |
213744 KB |
Output is correct |
4 |
Correct |
1426 ms |
215080 KB |
Output is correct |
5 |
Correct |
2063 ms |
199572 KB |
Output is correct |
6 |
Correct |
1384 ms |
199096 KB |
Output is correct |
7 |
Correct |
1086 ms |
199592 KB |
Output is correct |
8 |
Correct |
536 ms |
199076 KB |
Output is correct |
9 |
Correct |
969 ms |
213156 KB |
Output is correct |
10 |
Correct |
2779 ms |
217484 KB |
Output is correct |
11 |
Correct |
1061 ms |
200052 KB |
Output is correct |
12 |
Execution timed out |
4083 ms |
199172 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
172592 KB |
Output is correct |
2 |
Correct |
836 ms |
214808 KB |
Output is correct |
3 |
Correct |
3404 ms |
208216 KB |
Output is correct |
4 |
Correct |
1461 ms |
212100 KB |
Output is correct |
5 |
Correct |
1888 ms |
201164 KB |
Output is correct |
6 |
Correct |
1273 ms |
201004 KB |
Output is correct |
7 |
Correct |
1073 ms |
200012 KB |
Output is correct |
8 |
Correct |
609 ms |
200416 KB |
Output is correct |
9 |
Correct |
890 ms |
221372 KB |
Output is correct |
10 |
Correct |
3391 ms |
218476 KB |
Output is correct |
11 |
Correct |
1260 ms |
202460 KB |
Output is correct |
12 |
Execution timed out |
4113 ms |
199396 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
172524 KB |
Output is correct |
2 |
Correct |
74 ms |
172560 KB |
Output is correct |
3 |
Correct |
79 ms |
172644 KB |
Output is correct |
4 |
Correct |
95 ms |
172816 KB |
Output is correct |
5 |
Correct |
69 ms |
172728 KB |
Output is correct |
6 |
Correct |
89 ms |
172836 KB |
Output is correct |
7 |
Correct |
88 ms |
172700 KB |
Output is correct |
8 |
Correct |
88 ms |
172708 KB |
Output is correct |
9 |
Correct |
76 ms |
172544 KB |
Output is correct |
10 |
Correct |
70 ms |
172608 KB |
Output is correct |
11 |
Correct |
72 ms |
172568 KB |
Output is correct |
12 |
Correct |
70 ms |
172636 KB |
Output is correct |
13 |
Correct |
83 ms |
172652 KB |
Output is correct |
14 |
Correct |
83 ms |
172548 KB |
Output is correct |
15 |
Correct |
76 ms |
172624 KB |
Output is correct |
16 |
Correct |
82 ms |
172624 KB |
Output is correct |
17 |
Correct |
73 ms |
172628 KB |
Output is correct |
18 |
Correct |
75 ms |
172592 KB |
Output is correct |
19 |
Correct |
75 ms |
172612 KB |
Output is correct |
20 |
Correct |
83 ms |
172700 KB |
Output is correct |
21 |
Correct |
86 ms |
172536 KB |
Output is correct |
22 |
Correct |
72 ms |
172524 KB |
Output is correct |
23 |
Correct |
69 ms |
172536 KB |
Output is correct |
24 |
Correct |
74 ms |
172564 KB |
Output is correct |
25 |
Correct |
67 ms |
172544 KB |
Output is correct |
26 |
Correct |
81 ms |
172592 KB |
Output is correct |
27 |
Correct |
69 ms |
172616 KB |
Output is correct |
28 |
Correct |
77 ms |
172532 KB |
Output is correct |
29 |
Correct |
70 ms |
172664 KB |
Output is correct |
30 |
Correct |
502 ms |
202836 KB |
Output is correct |
31 |
Correct |
718 ms |
199712 KB |
Output is correct |
32 |
Correct |
673 ms |
213376 KB |
Output is correct |
33 |
Correct |
615 ms |
201292 KB |
Output is correct |
34 |
Correct |
589 ms |
200716 KB |
Output is correct |
35 |
Correct |
618 ms |
200540 KB |
Output is correct |
36 |
Correct |
501 ms |
200628 KB |
Output is correct |
37 |
Correct |
557 ms |
223264 KB |
Output is correct |
38 |
Correct |
660 ms |
218028 KB |
Output is correct |
39 |
Correct |
626 ms |
202644 KB |
Output is correct |
40 |
Correct |
653 ms |
199696 KB |
Output is correct |
41 |
Correct |
459 ms |
199536 KB |
Output is correct |
42 |
Correct |
521 ms |
200204 KB |
Output is correct |
43 |
Correct |
504 ms |
199804 KB |
Output is correct |
44 |
Correct |
546 ms |
199832 KB |
Output is correct |
45 |
Correct |
554 ms |
199684 KB |
Output is correct |
46 |
Correct |
82 ms |
172588 KB |
Output is correct |
47 |
Correct |
73 ms |
172592 KB |
Output is correct |
48 |
Correct |
67 ms |
172576 KB |
Output is correct |
49 |
Correct |
70 ms |
172584 KB |
Output is correct |
50 |
Correct |
68 ms |
172616 KB |
Output is correct |
51 |
Correct |
66 ms |
172648 KB |
Output is correct |
52 |
Correct |
618 ms |
202596 KB |
Output is correct |
53 |
Correct |
847 ms |
199864 KB |
Output is correct |
54 |
Correct |
612 ms |
220512 KB |
Output is correct |
55 |
Correct |
616 ms |
201112 KB |
Output is correct |
56 |
Correct |
702 ms |
200816 KB |
Output is correct |
57 |
Correct |
616 ms |
201064 KB |
Output is correct |
58 |
Correct |
511 ms |
200760 KB |
Output is correct |
59 |
Correct |
592 ms |
215728 KB |
Output is correct |
60 |
Correct |
765 ms |
218080 KB |
Output is correct |
61 |
Correct |
580 ms |
202656 KB |
Output is correct |
62 |
Correct |
845 ms |
199288 KB |
Output is correct |
63 |
Correct |
68 ms |
172620 KB |
Output is correct |
64 |
Correct |
67 ms |
172576 KB |
Output is correct |
65 |
Correct |
70 ms |
172568 KB |
Output is correct |
66 |
Correct |
84 ms |
172604 KB |
Output is correct |
67 |
Correct |
72 ms |
172556 KB |
Output is correct |
68 |
Correct |
76 ms |
172600 KB |
Output is correct |
69 |
Correct |
68 ms |
172580 KB |
Output is correct |
70 |
Correct |
66 ms |
172536 KB |
Output is correct |
71 |
Correct |
66 ms |
172604 KB |
Output is correct |
72 |
Correct |
85 ms |
172648 KB |
Output is correct |
73 |
Correct |
67 ms |
172584 KB |
Output is correct |
74 |
Correct |
73 ms |
172552 KB |
Output is correct |
75 |
Correct |
67 ms |
172620 KB |
Output is correct |
76 |
Correct |
67 ms |
172596 KB |
Output is correct |
77 |
Correct |
71 ms |
172688 KB |
Output is correct |
78 |
Correct |
69 ms |
172636 KB |
Output is correct |
79 |
Correct |
749 ms |
220116 KB |
Output is correct |
80 |
Correct |
3326 ms |
213744 KB |
Output is correct |
81 |
Correct |
1426 ms |
215080 KB |
Output is correct |
82 |
Correct |
2063 ms |
199572 KB |
Output is correct |
83 |
Correct |
1384 ms |
199096 KB |
Output is correct |
84 |
Correct |
1086 ms |
199592 KB |
Output is correct |
85 |
Correct |
536 ms |
199076 KB |
Output is correct |
86 |
Correct |
969 ms |
213156 KB |
Output is correct |
87 |
Correct |
2779 ms |
217484 KB |
Output is correct |
88 |
Correct |
1061 ms |
200052 KB |
Output is correct |
89 |
Execution timed out |
4083 ms |
199172 KB |
Time limit exceeded |
90 |
Halted |
0 ms |
0 KB |
- |