Submission #1068756

# Submission time Handle Problem Language Result Execution time Memory
1068756 2024-08-21T11:51:18 Z vjudge1 Sprinkler (JOI22_sprinkler) C++17
100 / 100
523 ms 52684 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=2e5+5;
const ll inf=2e18;
int n,q,f[maxN+1][41],L,h[maxN+1],parent[maxN+1];
vector<int> adj[maxN+1];
void dfs(int u,int p)
{
    parent[u]=p;
    for(auto v:adj[u])
    {
        if(v!=p)
        {
            dfs(v,u);
        }
    }
}
int main()
{
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>L;
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=1;i<=n;i++)
    {
        cin>>h[i];
        for(int j=0;j<=40;j++)
        {
            f[i][j]=1;
        }
    }
    dfs(1,0);
    cin>>q;
    while(q--)
    {
        int s;
        cin>>s;
        if(s==1)
        {
            int x,d,w;
            cin>>x>>d>>w;
            while(d>=0&&x>0)
            {
                if(x==1)
                {
                    while(d>=0)
                    {
                        f[x][d]=(1LL*f[x][d]*w)%L;
                        d--;
                    }
                }
                else
                {
                    f[x][d]=(1LL*f[x][d]*w)%L;
                    if(d>0)
                    {
                        f[x][d-1]=(1LL*f[x][d-1]*w)%L;
                    }
                }
                x=parent[x];
                d--;
            }
        }
        else
        {
            int x;
            cin>>x;
            int ans=h[x];
            int d=0;
            while(d<=40&&x>0)
            {
                ans=(1LL*ans*f[x][d])%L;
                x=parent[x];
                d++;
            }
            cout<<ans<<'\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4964 KB Output is correct
4 Correct 2 ms 5288 KB Output is correct
5 Correct 3 ms 5208 KB Output is correct
6 Correct 3 ms 5212 KB Output is correct
7 Correct 2 ms 5212 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 5036 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 4 ms 4968 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 408 ms 48468 KB Output is correct
3 Correct 231 ms 45392 KB Output is correct
4 Correct 338 ms 49748 KB Output is correct
5 Correct 310 ms 46912 KB Output is correct
6 Correct 234 ms 46992 KB Output is correct
7 Correct 207 ms 47188 KB Output is correct
8 Correct 191 ms 47812 KB Output is correct
9 Correct 442 ms 52684 KB Output is correct
10 Correct 247 ms 49408 KB Output is correct
11 Correct 388 ms 48532 KB Output is correct
12 Correct 236 ms 45396 KB Output is correct
13 Correct 144 ms 46020 KB Output is correct
14 Correct 156 ms 46020 KB Output is correct
15 Correct 159 ms 46096 KB Output is correct
16 Correct 158 ms 45904 KB Output is correct
17 Correct 174 ms 46568 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 3 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 408 ms 48468 KB Output is correct
3 Correct 231 ms 45392 KB Output is correct
4 Correct 338 ms 49748 KB Output is correct
5 Correct 310 ms 46912 KB Output is correct
6 Correct 234 ms 46992 KB Output is correct
7 Correct 207 ms 47188 KB Output is correct
8 Correct 191 ms 47812 KB Output is correct
9 Correct 442 ms 52684 KB Output is correct
10 Correct 247 ms 49408 KB Output is correct
11 Correct 388 ms 48532 KB Output is correct
12 Correct 236 ms 45396 KB Output is correct
13 Correct 144 ms 46020 KB Output is correct
14 Correct 156 ms 46020 KB Output is correct
15 Correct 159 ms 46096 KB Output is correct
16 Correct 158 ms 45904 KB Output is correct
17 Correct 174 ms 46568 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 3 ms 4956 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 427 ms 48636 KB Output is correct
25 Correct 243 ms 45392 KB Output is correct
26 Correct 371 ms 51028 KB Output is correct
27 Correct 322 ms 46932 KB Output is correct
28 Correct 283 ms 47244 KB Output is correct
29 Correct 218 ms 47184 KB Output is correct
30 Correct 213 ms 47812 KB Output is correct
31 Correct 477 ms 51560 KB Output is correct
32 Correct 279 ms 49388 KB Output is correct
33 Correct 446 ms 48468 KB Output is correct
34 Correct 256 ms 45408 KB Output is correct
35 Correct 2 ms 4956 KB Output is correct
36 Correct 3 ms 4956 KB Output is correct
37 Correct 2 ms 5148 KB Output is correct
38 Correct 2 ms 4956 KB Output is correct
39 Correct 2 ms 4952 KB Output is correct
40 Correct 2 ms 4956 KB Output is correct
41 Correct 2 ms 4956 KB Output is correct
42 Correct 3 ms 4952 KB Output is correct
43 Correct 2 ms 4956 KB Output is correct
44 Correct 2 ms 4956 KB Output is correct
45 Correct 2 ms 4956 KB Output is correct
46 Correct 3 ms 5016 KB Output is correct
47 Correct 2 ms 4956 KB Output is correct
48 Correct 2 ms 4956 KB Output is correct
49 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 523 ms 50120 KB Output is correct
3 Correct 492 ms 48212 KB Output is correct
4 Correct 410 ms 48976 KB Output is correct
5 Correct 377 ms 45464 KB Output is correct
6 Correct 234 ms 45652 KB Output is correct
7 Correct 213 ms 45776 KB Output is correct
8 Correct 177 ms 46020 KB Output is correct
9 Correct 477 ms 48976 KB Output is correct
10 Correct 468 ms 48888 KB Output is correct
11 Correct 431 ms 45740 KB Output is correct
12 Correct 428 ms 45140 KB Output is correct
13 Correct 260 ms 46008 KB Output is correct
14 Correct 270 ms 46416 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 503 ms 51340 KB Output is correct
3 Correct 492 ms 47660 KB Output is correct
4 Correct 434 ms 49492 KB Output is correct
5 Correct 371 ms 47084 KB Output is correct
6 Correct 231 ms 47184 KB Output is correct
7 Correct 212 ms 47048 KB Output is correct
8 Correct 194 ms 47468 KB Output is correct
9 Correct 506 ms 52432 KB Output is correct
10 Correct 478 ms 49480 KB Output is correct
11 Correct 418 ms 48468 KB Output is correct
12 Correct 430 ms 45380 KB Output is correct
13 Correct 314 ms 46160 KB Output is correct
14 Correct 278 ms 46672 KB Output is correct
15 Correct 2 ms 4952 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4964 KB Output is correct
4 Correct 2 ms 5288 KB Output is correct
5 Correct 3 ms 5208 KB Output is correct
6 Correct 3 ms 5212 KB Output is correct
7 Correct 2 ms 5212 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 5036 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 4 ms 4968 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
29 Correct 3 ms 4952 KB Output is correct
30 Correct 408 ms 48468 KB Output is correct
31 Correct 231 ms 45392 KB Output is correct
32 Correct 338 ms 49748 KB Output is correct
33 Correct 310 ms 46912 KB Output is correct
34 Correct 234 ms 46992 KB Output is correct
35 Correct 207 ms 47188 KB Output is correct
36 Correct 191 ms 47812 KB Output is correct
37 Correct 442 ms 52684 KB Output is correct
38 Correct 247 ms 49408 KB Output is correct
39 Correct 388 ms 48532 KB Output is correct
40 Correct 236 ms 45396 KB Output is correct
41 Correct 144 ms 46020 KB Output is correct
42 Correct 156 ms 46020 KB Output is correct
43 Correct 159 ms 46096 KB Output is correct
44 Correct 158 ms 45904 KB Output is correct
45 Correct 174 ms 46568 KB Output is correct
46 Correct 2 ms 4956 KB Output is correct
47 Correct 2 ms 4956 KB Output is correct
48 Correct 2 ms 4956 KB Output is correct
49 Correct 2 ms 4956 KB Output is correct
50 Correct 3 ms 4956 KB Output is correct
51 Correct 2 ms 4956 KB Output is correct
52 Correct 427 ms 48636 KB Output is correct
53 Correct 243 ms 45392 KB Output is correct
54 Correct 371 ms 51028 KB Output is correct
55 Correct 322 ms 46932 KB Output is correct
56 Correct 283 ms 47244 KB Output is correct
57 Correct 218 ms 47184 KB Output is correct
58 Correct 213 ms 47812 KB Output is correct
59 Correct 477 ms 51560 KB Output is correct
60 Correct 279 ms 49388 KB Output is correct
61 Correct 446 ms 48468 KB Output is correct
62 Correct 256 ms 45408 KB Output is correct
63 Correct 2 ms 4956 KB Output is correct
64 Correct 3 ms 4956 KB Output is correct
65 Correct 2 ms 5148 KB Output is correct
66 Correct 2 ms 4956 KB Output is correct
67 Correct 2 ms 4952 KB Output is correct
68 Correct 2 ms 4956 KB Output is correct
69 Correct 2 ms 4956 KB Output is correct
70 Correct 3 ms 4952 KB Output is correct
71 Correct 2 ms 4956 KB Output is correct
72 Correct 2 ms 4956 KB Output is correct
73 Correct 2 ms 4956 KB Output is correct
74 Correct 3 ms 5016 KB Output is correct
75 Correct 2 ms 4956 KB Output is correct
76 Correct 2 ms 4956 KB Output is correct
77 Correct 2 ms 4956 KB Output is correct
78 Correct 3 ms 4952 KB Output is correct
79 Correct 523 ms 50120 KB Output is correct
80 Correct 492 ms 48212 KB Output is correct
81 Correct 410 ms 48976 KB Output is correct
82 Correct 377 ms 45464 KB Output is correct
83 Correct 234 ms 45652 KB Output is correct
84 Correct 213 ms 45776 KB Output is correct
85 Correct 177 ms 46020 KB Output is correct
86 Correct 477 ms 48976 KB Output is correct
87 Correct 468 ms 48888 KB Output is correct
88 Correct 431 ms 45740 KB Output is correct
89 Correct 428 ms 45140 KB Output is correct
90 Correct 260 ms 46008 KB Output is correct
91 Correct 270 ms 46416 KB Output is correct
92 Correct 2 ms 4956 KB Output is correct
93 Correct 2 ms 4956 KB Output is correct
94 Correct 2 ms 4956 KB Output is correct
95 Correct 2 ms 4956 KB Output is correct
96 Correct 2 ms 4952 KB Output is correct
97 Correct 2 ms 4952 KB Output is correct
98 Correct 503 ms 51340 KB Output is correct
99 Correct 492 ms 47660 KB Output is correct
100 Correct 434 ms 49492 KB Output is correct
101 Correct 371 ms 47084 KB Output is correct
102 Correct 231 ms 47184 KB Output is correct
103 Correct 212 ms 47048 KB Output is correct
104 Correct 194 ms 47468 KB Output is correct
105 Correct 506 ms 52432 KB Output is correct
106 Correct 478 ms 49480 KB Output is correct
107 Correct 418 ms 48468 KB Output is correct
108 Correct 430 ms 45380 KB Output is correct
109 Correct 314 ms 46160 KB Output is correct
110 Correct 278 ms 46672 KB Output is correct
111 Correct 2 ms 4952 KB Output is correct
112 Correct 3 ms 4956 KB Output is correct
113 Correct 3 ms 4956 KB Output is correct
114 Correct 2 ms 4956 KB Output is correct
115 Correct 2 ms 4956 KB Output is correct
116 Correct 472 ms 46420 KB Output is correct
117 Correct 481 ms 45140 KB Output is correct
118 Correct 484 ms 50912 KB Output is correct
119 Correct 402 ms 47192 KB Output is correct
120 Correct 249 ms 46944 KB Output is correct
121 Correct 238 ms 47188 KB Output is correct
122 Correct 188 ms 47812 KB Output is correct
123 Correct 473 ms 52048 KB Output is correct
124 Correct 496 ms 47856 KB Output is correct
125 Correct 420 ms 48056 KB Output is correct
126 Correct 438 ms 45140 KB Output is correct
127 Correct 444 ms 45136 KB Output is correct
128 Correct 293 ms 46200 KB Output is correct
129 Correct 312 ms 46444 KB Output is correct