# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
721410 |
2023-04-10T20:42:42 Z |
lam |
Sprinkler (JOI22_sprinkler) |
C++14 |
|
828 ms |
95864 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e5 + 10;
int n,mod,q;
vector <int> adj[maxn];
int a[maxn];
int par[maxn];
int dp[maxn][41];
void dfs(int x, int p)
{
for (int i:adj[x])
if (i!=p)
{
par[i]=x;
dfs(i,x);
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cin>>n>>mod;
for (int i=1; i<n; i++)
{
int u,v; cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1,1);
par[1]=0;
for (int i=1; i<=n; i++) cin>>a[i];
cin>>q;
for (int i=1; i<=n; i++)
for (int j=0; j<=40; j++) dp[i][j]=1LL;
for (int i=1; i<=q; i++)
{
int t; cin>>t;
if (t==1)
{
int x,d,w; cin>>x>>d>>w;
for (int p = x; p>0&&d>=0; p=par[p], d--)
{
dp[p][d]=(dp[p][d]*w)%mod;
if (d>0) dp[p][d-1]=(dp[p][d-1]*w)%mod;
}
for (d--; d>=0; d--)
{
dp[1][d]=(dp[1][d]*w)%mod;
}
}
else
{
int x; cin>>x;
int ans=a[x]%mod;
for (int p=x, d=0; p>0&&d<=40; p=par[p], d++)
{
ans=(ans*dp[p][d])%mod;
}
cout<<ans<<'\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5024 KB |
Output is correct |
2 |
Correct |
3 ms |
5032 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5424 KB |
Output is correct |
5 |
Correct |
4 ms |
5332 KB |
Output is correct |
6 |
Correct |
4 ms |
5332 KB |
Output is correct |
7 |
Correct |
4 ms |
5428 KB |
Output is correct |
8 |
Correct |
4 ms |
5356 KB |
Output is correct |
9 |
Correct |
3 ms |
5036 KB |
Output is correct |
10 |
Correct |
3 ms |
5016 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
4 ms |
4948 KB |
Output is correct |
14 |
Correct |
4 ms |
4948 KB |
Output is correct |
15 |
Correct |
5 ms |
5032 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
4 ms |
5036 KB |
Output is correct |
18 |
Correct |
3 ms |
5028 KB |
Output is correct |
19 |
Correct |
4 ms |
5076 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
3 ms |
5028 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
4948 KB |
Output is correct |
26 |
Correct |
4 ms |
5036 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 |
654 ms |
85888 KB |
Output is correct |
3 |
Correct |
371 ms |
82696 KB |
Output is correct |
4 |
Correct |
548 ms |
86688 KB |
Output is correct |
5 |
Correct |
503 ms |
84172 KB |
Output is correct |
6 |
Correct |
363 ms |
84176 KB |
Output is correct |
7 |
Correct |
323 ms |
84636 KB |
Output is correct |
8 |
Correct |
307 ms |
84712 KB |
Output is correct |
9 |
Correct |
746 ms |
90160 KB |
Output is correct |
10 |
Correct |
406 ms |
86560 KB |
Output is correct |
11 |
Correct |
628 ms |
85908 KB |
Output is correct |
12 |
Correct |
401 ms |
82704 KB |
Output is correct |
13 |
Correct |
231 ms |
83016 KB |
Output is correct |
14 |
Correct |
262 ms |
82992 KB |
Output is correct |
15 |
Correct |
241 ms |
82996 KB |
Output is correct |
16 |
Correct |
244 ms |
82984 KB |
Output is correct |
17 |
Correct |
281 ms |
83488 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 |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
5032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
654 ms |
85888 KB |
Output is correct |
3 |
Correct |
371 ms |
82696 KB |
Output is correct |
4 |
Correct |
548 ms |
86688 KB |
Output is correct |
5 |
Correct |
503 ms |
84172 KB |
Output is correct |
6 |
Correct |
363 ms |
84176 KB |
Output is correct |
7 |
Correct |
323 ms |
84636 KB |
Output is correct |
8 |
Correct |
307 ms |
84712 KB |
Output is correct |
9 |
Correct |
746 ms |
90160 KB |
Output is correct |
10 |
Correct |
406 ms |
86560 KB |
Output is correct |
11 |
Correct |
628 ms |
85908 KB |
Output is correct |
12 |
Correct |
401 ms |
82704 KB |
Output is correct |
13 |
Correct |
231 ms |
83016 KB |
Output is correct |
14 |
Correct |
262 ms |
82992 KB |
Output is correct |
15 |
Correct |
241 ms |
82996 KB |
Output is correct |
16 |
Correct |
244 ms |
82984 KB |
Output is correct |
17 |
Correct |
281 ms |
83488 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 |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
5032 KB |
Output is correct |
23 |
Correct |
3 ms |
5032 KB |
Output is correct |
24 |
Correct |
618 ms |
85868 KB |
Output is correct |
25 |
Correct |
438 ms |
82704 KB |
Output is correct |
26 |
Correct |
546 ms |
88340 KB |
Output is correct |
27 |
Correct |
498 ms |
84400 KB |
Output is correct |
28 |
Correct |
375 ms |
84392 KB |
Output is correct |
29 |
Correct |
340 ms |
84488 KB |
Output is correct |
30 |
Correct |
265 ms |
84776 KB |
Output is correct |
31 |
Correct |
703 ms |
88628 KB |
Output is correct |
32 |
Correct |
409 ms |
86576 KB |
Output is correct |
33 |
Correct |
583 ms |
85872 KB |
Output is correct |
34 |
Correct |
418 ms |
82636 KB |
Output is correct |
35 |
Correct |
3 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
3 ms |
4948 KB |
Output is correct |
38 |
Correct |
3 ms |
4948 KB |
Output is correct |
39 |
Correct |
3 ms |
5036 KB |
Output is correct |
40 |
Correct |
3 ms |
5028 KB |
Output is correct |
41 |
Correct |
3 ms |
5032 KB |
Output is correct |
42 |
Correct |
3 ms |
5032 KB |
Output is correct |
43 |
Correct |
3 ms |
4948 KB |
Output is correct |
44 |
Correct |
3 ms |
4948 KB |
Output is correct |
45 |
Correct |
3 ms |
4948 KB |
Output is correct |
46 |
Correct |
4 ms |
5028 KB |
Output is correct |
47 |
Correct |
3 ms |
5028 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 |
5028 KB |
Output is correct |
2 |
Correct |
713 ms |
88236 KB |
Output is correct |
3 |
Correct |
828 ms |
85328 KB |
Output is correct |
4 |
Correct |
600 ms |
86148 KB |
Output is correct |
5 |
Correct |
587 ms |
82676 KB |
Output is correct |
6 |
Correct |
440 ms |
82880 KB |
Output is correct |
7 |
Correct |
406 ms |
82964 KB |
Output is correct |
8 |
Correct |
263 ms |
83188 KB |
Output is correct |
9 |
Correct |
732 ms |
85872 KB |
Output is correct |
10 |
Correct |
775 ms |
86488 KB |
Output is correct |
11 |
Correct |
617 ms |
83124 KB |
Output is correct |
12 |
Correct |
724 ms |
82364 KB |
Output is correct |
13 |
Correct |
427 ms |
83260 KB |
Output is correct |
14 |
Correct |
440 ms |
84032 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
5028 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
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 |
709 ms |
88348 KB |
Output is correct |
3 |
Correct |
750 ms |
84488 KB |
Output is correct |
4 |
Correct |
622 ms |
86364 KB |
Output is correct |
5 |
Correct |
561 ms |
84296 KB |
Output is correct |
6 |
Correct |
404 ms |
84424 KB |
Output is correct |
7 |
Correct |
370 ms |
84436 KB |
Output is correct |
8 |
Correct |
267 ms |
84484 KB |
Output is correct |
9 |
Correct |
673 ms |
89740 KB |
Output is correct |
10 |
Correct |
772 ms |
86608 KB |
Output is correct |
11 |
Correct |
595 ms |
85888 KB |
Output is correct |
12 |
Correct |
652 ms |
82776 KB |
Output is correct |
13 |
Correct |
498 ms |
83348 KB |
Output is correct |
14 |
Correct |
468 ms |
84172 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
5028 KB |
Output is correct |
17 |
Correct |
3 ms |
5036 KB |
Output is correct |
18 |
Correct |
3 ms |
5024 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5024 KB |
Output is correct |
2 |
Correct |
3 ms |
5032 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5424 KB |
Output is correct |
5 |
Correct |
4 ms |
5332 KB |
Output is correct |
6 |
Correct |
4 ms |
5332 KB |
Output is correct |
7 |
Correct |
4 ms |
5428 KB |
Output is correct |
8 |
Correct |
4 ms |
5356 KB |
Output is correct |
9 |
Correct |
3 ms |
5036 KB |
Output is correct |
10 |
Correct |
3 ms |
5016 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
4 ms |
4948 KB |
Output is correct |
14 |
Correct |
4 ms |
4948 KB |
Output is correct |
15 |
Correct |
5 ms |
5032 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
4 ms |
5036 KB |
Output is correct |
18 |
Correct |
3 ms |
5028 KB |
Output is correct |
19 |
Correct |
4 ms |
5076 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
3 ms |
5028 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
4948 KB |
Output is correct |
26 |
Correct |
4 ms |
5036 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 |
654 ms |
85888 KB |
Output is correct |
31 |
Correct |
371 ms |
82696 KB |
Output is correct |
32 |
Correct |
548 ms |
86688 KB |
Output is correct |
33 |
Correct |
503 ms |
84172 KB |
Output is correct |
34 |
Correct |
363 ms |
84176 KB |
Output is correct |
35 |
Correct |
323 ms |
84636 KB |
Output is correct |
36 |
Correct |
307 ms |
84712 KB |
Output is correct |
37 |
Correct |
746 ms |
90160 KB |
Output is correct |
38 |
Correct |
406 ms |
86560 KB |
Output is correct |
39 |
Correct |
628 ms |
85908 KB |
Output is correct |
40 |
Correct |
401 ms |
82704 KB |
Output is correct |
41 |
Correct |
231 ms |
83016 KB |
Output is correct |
42 |
Correct |
262 ms |
82992 KB |
Output is correct |
43 |
Correct |
241 ms |
82996 KB |
Output is correct |
44 |
Correct |
244 ms |
82984 KB |
Output is correct |
45 |
Correct |
281 ms |
83488 KB |
Output is correct |
46 |
Correct |
3 ms |
4948 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 |
50 |
Correct |
4 ms |
5032 KB |
Output is correct |
51 |
Correct |
3 ms |
5032 KB |
Output is correct |
52 |
Correct |
618 ms |
85868 KB |
Output is correct |
53 |
Correct |
438 ms |
82704 KB |
Output is correct |
54 |
Correct |
546 ms |
88340 KB |
Output is correct |
55 |
Correct |
498 ms |
84400 KB |
Output is correct |
56 |
Correct |
375 ms |
84392 KB |
Output is correct |
57 |
Correct |
340 ms |
84488 KB |
Output is correct |
58 |
Correct |
265 ms |
84776 KB |
Output is correct |
59 |
Correct |
703 ms |
88628 KB |
Output is correct |
60 |
Correct |
409 ms |
86576 KB |
Output is correct |
61 |
Correct |
583 ms |
85872 KB |
Output is correct |
62 |
Correct |
418 ms |
82636 KB |
Output is correct |
63 |
Correct |
3 ms |
4948 KB |
Output is correct |
64 |
Correct |
3 ms |
4948 KB |
Output is correct |
65 |
Correct |
3 ms |
4948 KB |
Output is correct |
66 |
Correct |
3 ms |
4948 KB |
Output is correct |
67 |
Correct |
3 ms |
5036 KB |
Output is correct |
68 |
Correct |
3 ms |
5028 KB |
Output is correct |
69 |
Correct |
3 ms |
5032 KB |
Output is correct |
70 |
Correct |
3 ms |
5032 KB |
Output is correct |
71 |
Correct |
3 ms |
4948 KB |
Output is correct |
72 |
Correct |
3 ms |
4948 KB |
Output is correct |
73 |
Correct |
3 ms |
4948 KB |
Output is correct |
74 |
Correct |
4 ms |
5028 KB |
Output is correct |
75 |
Correct |
3 ms |
5028 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 |
5028 KB |
Output is correct |
79 |
Correct |
713 ms |
88236 KB |
Output is correct |
80 |
Correct |
828 ms |
85328 KB |
Output is correct |
81 |
Correct |
600 ms |
86148 KB |
Output is correct |
82 |
Correct |
587 ms |
82676 KB |
Output is correct |
83 |
Correct |
440 ms |
82880 KB |
Output is correct |
84 |
Correct |
406 ms |
82964 KB |
Output is correct |
85 |
Correct |
263 ms |
83188 KB |
Output is correct |
86 |
Correct |
732 ms |
85872 KB |
Output is correct |
87 |
Correct |
775 ms |
86488 KB |
Output is correct |
88 |
Correct |
617 ms |
83124 KB |
Output is correct |
89 |
Correct |
724 ms |
82364 KB |
Output is correct |
90 |
Correct |
427 ms |
83260 KB |
Output is correct |
91 |
Correct |
440 ms |
84032 KB |
Output is correct |
92 |
Correct |
3 ms |
4948 KB |
Output is correct |
93 |
Correct |
4 ms |
5028 KB |
Output is correct |
94 |
Correct |
3 ms |
4948 KB |
Output is correct |
95 |
Correct |
3 ms |
4948 KB |
Output is correct |
96 |
Correct |
3 ms |
4948 KB |
Output is correct |
97 |
Correct |
3 ms |
4948 KB |
Output is correct |
98 |
Correct |
709 ms |
88348 KB |
Output is correct |
99 |
Correct |
750 ms |
84488 KB |
Output is correct |
100 |
Correct |
622 ms |
86364 KB |
Output is correct |
101 |
Correct |
561 ms |
84296 KB |
Output is correct |
102 |
Correct |
404 ms |
84424 KB |
Output is correct |
103 |
Correct |
370 ms |
84436 KB |
Output is correct |
104 |
Correct |
267 ms |
84484 KB |
Output is correct |
105 |
Correct |
673 ms |
89740 KB |
Output is correct |
106 |
Correct |
772 ms |
86608 KB |
Output is correct |
107 |
Correct |
595 ms |
85888 KB |
Output is correct |
108 |
Correct |
652 ms |
82776 KB |
Output is correct |
109 |
Correct |
498 ms |
83348 KB |
Output is correct |
110 |
Correct |
468 ms |
84172 KB |
Output is correct |
111 |
Correct |
3 ms |
4948 KB |
Output is correct |
112 |
Correct |
3 ms |
5028 KB |
Output is correct |
113 |
Correct |
3 ms |
5036 KB |
Output is correct |
114 |
Correct |
3 ms |
5024 KB |
Output is correct |
115 |
Correct |
3 ms |
4948 KB |
Output is correct |
116 |
Correct |
665 ms |
89332 KB |
Output is correct |
117 |
Correct |
698 ms |
92036 KB |
Output is correct |
118 |
Correct |
668 ms |
95864 KB |
Output is correct |
119 |
Correct |
620 ms |
91704 KB |
Output is correct |
120 |
Correct |
410 ms |
91324 KB |
Output is correct |
121 |
Correct |
410 ms |
92092 KB |
Output is correct |
122 |
Correct |
302 ms |
92260 KB |
Output is correct |
123 |
Correct |
666 ms |
94640 KB |
Output is correct |
124 |
Correct |
755 ms |
93996 KB |
Output is correct |
125 |
Correct |
697 ms |
90684 KB |
Output is correct |
126 |
Correct |
692 ms |
91808 KB |
Output is correct |
127 |
Correct |
735 ms |
92464 KB |
Output is correct |
128 |
Correct |
573 ms |
93076 KB |
Output is correct |
129 |
Correct |
556 ms |
94000 KB |
Output is correct |