Submission #970627

# Submission time Handle Problem Language Result Execution time Memory
970627 2024-04-26T21:07:50 Z MarwenElarbi Sprinkler (JOI22_sprinkler) C++17
100 / 100
1330 ms 103184 KB
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200005];
long long h[200005];
long long parent[200005];
long long mul[200005][45];
int mod;
void dfs(int x,int p){
    for(auto u:adj[x]){
        if(u==p) continue;
        parent[u]=x;
        dfs(u,x);
    }
    return;
}
void update(int x,int d,int w){
    if(d==-1)return;
    if(x==0){
        for (int i = 0; i <= d; ++i)
        {
            mul[x][i]=mul[x][i]*w%mod;
        }
        //if(x==0) cout <<"nav"<<" "<<mul[0][0]<<endl;
        return;
    }
    update(parent[x],d-1,w);
    mul[x][d]=mul[x][d]*w%mod;
    if(d) mul[x][d-1]=mul[x][d-1]*w%mod;

}
long long query(int x)
{
    long long ans=h[x];
    int cur=x;
    for (int i = 0; i <= 40; ++i)
    {
        ans=ans*mul[cur][i]%mod;
        if(cur==0) return ans;
        cur=parent[cur];
    }   
    return ans;
}
int main() {
    int n;
    cin>>n>>mod;
    for (int i = 0; i < n-1; ++i)
    {
        int x,y;
        cin>>x>>y;
        x--;y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < 41; ++j)
        {
            mul[i][j]=1;
        }
        cin>>h[i];
    }
    dfs(0,-1);
    int q;
    cin>>q;
    while(q--){
        int c;
        cin>>c;
        if(c==1){
            int x,d,w;
            cin>>x>>d>>w;
            x--;
            update(x,d,w);
        }else{
            int x;
            cin>>x;
            x--;
            cout << query(x)<<endl;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 4 ms 10844 KB Output is correct
5 Correct 5 ms 10844 KB Output is correct
6 Correct 4 ms 10844 KB Output is correct
7 Correct 4 ms 10844 KB Output is correct
8 Correct 4 ms 10844 KB Output is correct
9 Correct 3 ms 8540 KB Output is correct
10 Correct 3 ms 8540 KB Output is correct
11 Correct 3 ms 8536 KB Output is correct
12 Correct 3 ms 8540 KB Output is correct
13 Correct 4 ms 8796 KB Output is correct
14 Correct 3 ms 8540 KB Output is correct
15 Correct 4 ms 8640 KB Output is correct
16 Correct 3 ms 8540 KB Output is correct
17 Correct 3 ms 8780 KB Output is correct
18 Correct 3 ms 8540 KB Output is correct
19 Correct 2 ms 8540 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 3 ms 8540 KB Output is correct
22 Correct 3 ms 8540 KB Output is correct
23 Correct 3 ms 8540 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 3 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 3 ms 8540 KB Output is correct
28 Correct 3 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 1043 ms 96716 KB Output is correct
3 Correct 592 ms 97364 KB Output is correct
4 Correct 847 ms 100948 KB Output is correct
5 Correct 803 ms 96984 KB Output is correct
6 Correct 748 ms 96492 KB Output is correct
7 Correct 712 ms 97360 KB Output is correct
8 Correct 664 ms 97844 KB Output is correct
9 Correct 1121 ms 103184 KB Output is correct
10 Correct 588 ms 102784 KB Output is correct
11 Correct 1049 ms 96760 KB Output is correct
12 Correct 565 ms 97232 KB Output is correct
13 Correct 489 ms 97468 KB Output is correct
14 Correct 491 ms 98304 KB Output is correct
15 Correct 518 ms 97472 KB Output is correct
16 Correct 495 ms 97872 KB Output is correct
17 Correct 502 ms 98720 KB Output is correct
18 Correct 3 ms 8540 KB Output is correct
19 Correct 3 ms 8540 KB Output is correct
20 Correct 3 ms 8784 KB Output is correct
21 Correct 3 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 1043 ms 96716 KB Output is correct
3 Correct 592 ms 97364 KB Output is correct
4 Correct 847 ms 100948 KB Output is correct
5 Correct 803 ms 96984 KB Output is correct
6 Correct 748 ms 96492 KB Output is correct
7 Correct 712 ms 97360 KB Output is correct
8 Correct 664 ms 97844 KB Output is correct
9 Correct 1121 ms 103184 KB Output is correct
10 Correct 588 ms 102784 KB Output is correct
11 Correct 1049 ms 96760 KB Output is correct
12 Correct 565 ms 97232 KB Output is correct
13 Correct 489 ms 97468 KB Output is correct
14 Correct 491 ms 98304 KB Output is correct
15 Correct 518 ms 97472 KB Output is correct
16 Correct 495 ms 97872 KB Output is correct
17 Correct 502 ms 98720 KB Output is correct
18 Correct 3 ms 8540 KB Output is correct
19 Correct 3 ms 8540 KB Output is correct
20 Correct 3 ms 8784 KB Output is correct
21 Correct 3 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 2 ms 8540 KB Output is correct
24 Correct 1083 ms 96636 KB Output is correct
25 Correct 581 ms 97360 KB Output is correct
26 Correct 902 ms 102996 KB Output is correct
27 Correct 862 ms 97072 KB Output is correct
28 Correct 696 ms 97152 KB Output is correct
29 Correct 676 ms 96696 KB Output is correct
30 Correct 652 ms 98016 KB Output is correct
31 Correct 1196 ms 101176 KB Output is correct
32 Correct 597 ms 102852 KB Output is correct
33 Correct 1074 ms 96784 KB Output is correct
34 Correct 636 ms 97396 KB Output is correct
35 Correct 2 ms 8536 KB Output is correct
36 Correct 2 ms 8540 KB Output is correct
37 Correct 3 ms 8796 KB Output is correct
38 Correct 3 ms 8792 KB Output is correct
39 Correct 3 ms 8796 KB Output is correct
40 Correct 2 ms 8776 KB Output is correct
41 Correct 3 ms 8540 KB Output is correct
42 Correct 2 ms 8540 KB Output is correct
43 Correct 3 ms 8776 KB Output is correct
44 Correct 3 ms 8796 KB Output is correct
45 Correct 2 ms 8540 KB Output is correct
46 Correct 2 ms 8540 KB Output is correct
47 Correct 3 ms 8540 KB Output is correct
48 Correct 2 ms 8540 KB Output is correct
49 Correct 2 ms 8772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 1192 ms 100124 KB Output is correct
3 Correct 1208 ms 99332 KB Output is correct
4 Correct 965 ms 99148 KB Output is correct
5 Correct 878 ms 94300 KB Output is correct
6 Correct 703 ms 94060 KB Output is correct
7 Correct 731 ms 94232 KB Output is correct
8 Correct 623 ms 94920 KB Output is correct
9 Correct 1169 ms 98064 KB Output is correct
10 Correct 1129 ms 99916 KB Output is correct
11 Correct 1029 ms 93756 KB Output is correct
12 Correct 861 ms 94432 KB Output is correct
13 Correct 694 ms 95464 KB Output is correct
14 Correct 671 ms 96056 KB Output is correct
15 Correct 3 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 2 ms 8792 KB Output is correct
19 Correct 3 ms 8612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 1184 ms 100464 KB Output is correct
3 Correct 1197 ms 98408 KB Output is correct
4 Correct 1014 ms 99328 KB Output is correct
5 Correct 866 ms 95892 KB Output is correct
6 Correct 751 ms 95680 KB Output is correct
7 Correct 733 ms 95480 KB Output is correct
8 Correct 628 ms 95684 KB Output is correct
9 Correct 1128 ms 102224 KB Output is correct
10 Correct 1209 ms 100708 KB Output is correct
11 Correct 1025 ms 96448 KB Output is correct
12 Correct 900 ms 94840 KB Output is correct
13 Correct 638 ms 95572 KB Output is correct
14 Correct 641 ms 96052 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8780 KB Output is correct
18 Correct 3 ms 8552 KB Output is correct
19 Correct 3 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 4 ms 10844 KB Output is correct
5 Correct 5 ms 10844 KB Output is correct
6 Correct 4 ms 10844 KB Output is correct
7 Correct 4 ms 10844 KB Output is correct
8 Correct 4 ms 10844 KB Output is correct
9 Correct 3 ms 8540 KB Output is correct
10 Correct 3 ms 8540 KB Output is correct
11 Correct 3 ms 8536 KB Output is correct
12 Correct 3 ms 8540 KB Output is correct
13 Correct 4 ms 8796 KB Output is correct
14 Correct 3 ms 8540 KB Output is correct
15 Correct 4 ms 8640 KB Output is correct
16 Correct 3 ms 8540 KB Output is correct
17 Correct 3 ms 8780 KB Output is correct
18 Correct 3 ms 8540 KB Output is correct
19 Correct 2 ms 8540 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 3 ms 8540 KB Output is correct
22 Correct 3 ms 8540 KB Output is correct
23 Correct 3 ms 8540 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 3 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 3 ms 8540 KB Output is correct
28 Correct 3 ms 8536 KB Output is correct
29 Correct 2 ms 8536 KB Output is correct
30 Correct 1043 ms 96716 KB Output is correct
31 Correct 592 ms 97364 KB Output is correct
32 Correct 847 ms 100948 KB Output is correct
33 Correct 803 ms 96984 KB Output is correct
34 Correct 748 ms 96492 KB Output is correct
35 Correct 712 ms 97360 KB Output is correct
36 Correct 664 ms 97844 KB Output is correct
37 Correct 1121 ms 103184 KB Output is correct
38 Correct 588 ms 102784 KB Output is correct
39 Correct 1049 ms 96760 KB Output is correct
40 Correct 565 ms 97232 KB Output is correct
41 Correct 489 ms 97468 KB Output is correct
42 Correct 491 ms 98304 KB Output is correct
43 Correct 518 ms 97472 KB Output is correct
44 Correct 495 ms 97872 KB Output is correct
45 Correct 502 ms 98720 KB Output is correct
46 Correct 3 ms 8540 KB Output is correct
47 Correct 3 ms 8540 KB Output is correct
48 Correct 3 ms 8784 KB Output is correct
49 Correct 3 ms 8796 KB Output is correct
50 Correct 2 ms 8796 KB Output is correct
51 Correct 2 ms 8540 KB Output is correct
52 Correct 1083 ms 96636 KB Output is correct
53 Correct 581 ms 97360 KB Output is correct
54 Correct 902 ms 102996 KB Output is correct
55 Correct 862 ms 97072 KB Output is correct
56 Correct 696 ms 97152 KB Output is correct
57 Correct 676 ms 96696 KB Output is correct
58 Correct 652 ms 98016 KB Output is correct
59 Correct 1196 ms 101176 KB Output is correct
60 Correct 597 ms 102852 KB Output is correct
61 Correct 1074 ms 96784 KB Output is correct
62 Correct 636 ms 97396 KB Output is correct
63 Correct 2 ms 8536 KB Output is correct
64 Correct 2 ms 8540 KB Output is correct
65 Correct 3 ms 8796 KB Output is correct
66 Correct 3 ms 8792 KB Output is correct
67 Correct 3 ms 8796 KB Output is correct
68 Correct 2 ms 8776 KB Output is correct
69 Correct 3 ms 8540 KB Output is correct
70 Correct 2 ms 8540 KB Output is correct
71 Correct 3 ms 8776 KB Output is correct
72 Correct 3 ms 8796 KB Output is correct
73 Correct 2 ms 8540 KB Output is correct
74 Correct 2 ms 8540 KB Output is correct
75 Correct 3 ms 8540 KB Output is correct
76 Correct 2 ms 8540 KB Output is correct
77 Correct 2 ms 8772 KB Output is correct
78 Correct 2 ms 8536 KB Output is correct
79 Correct 1192 ms 100124 KB Output is correct
80 Correct 1208 ms 99332 KB Output is correct
81 Correct 965 ms 99148 KB Output is correct
82 Correct 878 ms 94300 KB Output is correct
83 Correct 703 ms 94060 KB Output is correct
84 Correct 731 ms 94232 KB Output is correct
85 Correct 623 ms 94920 KB Output is correct
86 Correct 1169 ms 98064 KB Output is correct
87 Correct 1129 ms 99916 KB Output is correct
88 Correct 1029 ms 93756 KB Output is correct
89 Correct 861 ms 94432 KB Output is correct
90 Correct 694 ms 95464 KB Output is correct
91 Correct 671 ms 96056 KB Output is correct
92 Correct 3 ms 8540 KB Output is correct
93 Correct 2 ms 8540 KB Output is correct
94 Correct 2 ms 8540 KB Output is correct
95 Correct 2 ms 8792 KB Output is correct
96 Correct 3 ms 8612 KB Output is correct
97 Correct 2 ms 8540 KB Output is correct
98 Correct 1184 ms 100464 KB Output is correct
99 Correct 1197 ms 98408 KB Output is correct
100 Correct 1014 ms 99328 KB Output is correct
101 Correct 866 ms 95892 KB Output is correct
102 Correct 751 ms 95680 KB Output is correct
103 Correct 733 ms 95480 KB Output is correct
104 Correct 628 ms 95684 KB Output is correct
105 Correct 1128 ms 102224 KB Output is correct
106 Correct 1209 ms 100708 KB Output is correct
107 Correct 1025 ms 96448 KB Output is correct
108 Correct 900 ms 94840 KB Output is correct
109 Correct 638 ms 95572 KB Output is correct
110 Correct 641 ms 96052 KB Output is correct
111 Correct 2 ms 8540 KB Output is correct
112 Correct 2 ms 8796 KB Output is correct
113 Correct 2 ms 8780 KB Output is correct
114 Correct 3 ms 8552 KB Output is correct
115 Correct 3 ms 8540 KB Output is correct
116 Correct 1131 ms 94820 KB Output is correct
117 Correct 935 ms 97252 KB Output is correct
118 Correct 1044 ms 102980 KB Output is correct
119 Correct 903 ms 97248 KB Output is correct
120 Correct 774 ms 96736 KB Output is correct
121 Correct 822 ms 97308 KB Output is correct
122 Correct 669 ms 97880 KB Output is correct
123 Correct 1168 ms 101796 KB Output is correct
124 Correct 1330 ms 100980 KB Output is correct
125 Correct 1062 ms 96260 KB Output is correct
126 Correct 999 ms 97160 KB Output is correct
127 Correct 1018 ms 98128 KB Output is correct
128 Correct 826 ms 98520 KB Output is correct
129 Correct 834 ms 99004 KB Output is correct