Submission #892585

# Submission time Handle Problem Language Result Execution time Memory
892585 2023-12-25T14:29:33 Z Aiperiii Sprinkler (JOI22_sprinkler) C++14
100 / 100
1189 ms 101140 KB
#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
const int N=2e5+5;
vector <int> g[N];
int p[N];
int dp[N][50];
void dfs(int v,int par){
    p[v]=par;
    for(auto to : g[v]){
        if(to!=par)dfs(to,v);
    }
}
signed main(){
    int n,l;
    cin>>n>>l;
    for(int i=0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<=40;j++){
            dp[i][j]=1;
        }
    }
    dfs(1,0);
    vector <int> h(n+1);
    for(int i=1;i<=n;i++){
        cin>>h[i];
        dp[i][0]=h[i];
    }
    
    int q;cin>>q;
    while(q--){
        int type,v,d,x;
        cin>>type;
        if(type==1){
            cin>>v>>d>>x;
            while(v>=1 && d>=0){
                dp[v][d]=(dp[v][d])*x%l;
                d--;
                if(d<0)break;
                dp[v][d]=(dp[v][d])*x%l;
                if(p[v]!=0)v=p[v];
                else{
                    d--;
                    if(d<0)break;
                }
            }
        }
        else{
            cin>>v;
            int ans=1;
            for(int i=0;i<=40;i++){
                if(v>=1)ans=ans*dp[v][i]%l;
                v=p[v];
            }
            cout<<ans<<"\n";
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 2 ms 6828 KB Output is correct
4 Correct 4 ms 9052 KB Output is correct
5 Correct 3 ms 9052 KB Output is correct
6 Correct 3 ms 9052 KB Output is correct
7 Correct 3 ms 9052 KB Output is correct
8 Correct 3 ms 9052 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 3 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 3 ms 6748 KB Output is correct
18 Correct 3 ms 6748 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 2 ms 6588 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6748 KB Output is correct
25 Correct 3 ms 6748 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 2 ms 6820 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 956 ms 97452 KB Output is correct
3 Correct 602 ms 94244 KB Output is correct
4 Correct 803 ms 98032 KB Output is correct
5 Correct 770 ms 95996 KB Output is correct
6 Correct 748 ms 95824 KB Output is correct
7 Correct 702 ms 95988 KB Output is correct
8 Correct 662 ms 96352 KB Output is correct
9 Correct 1012 ms 101140 KB Output is correct
10 Correct 599 ms 97700 KB Output is correct
11 Correct 965 ms 97420 KB Output is correct
12 Correct 586 ms 94384 KB Output is correct
13 Correct 500 ms 94356 KB Output is correct
14 Correct 502 ms 94488 KB Output is correct
15 Correct 495 ms 94648 KB Output is correct
16 Correct 509 ms 94540 KB Output is correct
17 Correct 515 ms 95312 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 3 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 956 ms 97452 KB Output is correct
3 Correct 602 ms 94244 KB Output is correct
4 Correct 803 ms 98032 KB Output is correct
5 Correct 770 ms 95996 KB Output is correct
6 Correct 748 ms 95824 KB Output is correct
7 Correct 702 ms 95988 KB Output is correct
8 Correct 662 ms 96352 KB Output is correct
9 Correct 1012 ms 101140 KB Output is correct
10 Correct 599 ms 97700 KB Output is correct
11 Correct 965 ms 97420 KB Output is correct
12 Correct 586 ms 94384 KB Output is correct
13 Correct 500 ms 94356 KB Output is correct
14 Correct 502 ms 94488 KB Output is correct
15 Correct 495 ms 94648 KB Output is correct
16 Correct 509 ms 94540 KB Output is correct
17 Correct 515 ms 95312 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 3 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 943 ms 97368 KB Output is correct
25 Correct 600 ms 94100 KB Output is correct
26 Correct 797 ms 99400 KB Output is correct
27 Correct 756 ms 95828 KB Output is correct
28 Correct 703 ms 95836 KB Output is correct
29 Correct 692 ms 96104 KB Output is correct
30 Correct 655 ms 96240 KB Output is correct
31 Correct 1006 ms 99936 KB Output is correct
32 Correct 592 ms 98040 KB Output is correct
33 Correct 951 ms 97304 KB Output is correct
34 Correct 592 ms 94260 KB Output is correct
35 Correct 2 ms 6744 KB Output is correct
36 Correct 2 ms 6748 KB Output is correct
37 Correct 2 ms 6748 KB Output is correct
38 Correct 2 ms 6748 KB Output is correct
39 Correct 2 ms 6836 KB Output is correct
40 Correct 2 ms 6744 KB Output is correct
41 Correct 2 ms 6748 KB Output is correct
42 Correct 2 ms 6748 KB Output is correct
43 Correct 2 ms 6748 KB Output is correct
44 Correct 2 ms 6748 KB Output is correct
45 Correct 2 ms 6748 KB Output is correct
46 Correct 2 ms 6748 KB Output is correct
47 Correct 2 ms 6748 KB Output is correct
48 Correct 3 ms 6748 KB Output is correct
49 Correct 2 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1078 ms 98472 KB Output is correct
3 Correct 856 ms 96576 KB Output is correct
4 Correct 893 ms 97300 KB Output is correct
5 Correct 796 ms 94136 KB Output is correct
6 Correct 707 ms 94408 KB Output is correct
7 Correct 689 ms 94728 KB Output is correct
8 Correct 643 ms 94932 KB Output is correct
9 Correct 1020 ms 97296 KB Output is correct
10 Correct 865 ms 97672 KB Output is correct
11 Correct 954 ms 94508 KB Output is correct
12 Correct 706 ms 94032 KB Output is correct
13 Correct 577 ms 94800 KB Output is correct
14 Correct 574 ms 95592 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 3 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1034 ms 99644 KB Output is correct
3 Correct 855 ms 95980 KB Output is correct
4 Correct 893 ms 98216 KB Output is correct
5 Correct 783 ms 95852 KB Output is correct
6 Correct 722 ms 95924 KB Output is correct
7 Correct 699 ms 95932 KB Output is correct
8 Correct 636 ms 95936 KB Output is correct
9 Correct 1116 ms 100996 KB Output is correct
10 Correct 850 ms 98060 KB Output is correct
11 Correct 998 ms 97180 KB Output is correct
12 Correct 682 ms 94236 KB Output is correct
13 Correct 576 ms 95024 KB Output is correct
14 Correct 596 ms 95716 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 3 ms 6904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 2 ms 6828 KB Output is correct
4 Correct 4 ms 9052 KB Output is correct
5 Correct 3 ms 9052 KB Output is correct
6 Correct 3 ms 9052 KB Output is correct
7 Correct 3 ms 9052 KB Output is correct
8 Correct 3 ms 9052 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 3 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 3 ms 6748 KB Output is correct
18 Correct 3 ms 6748 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 2 ms 6588 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6748 KB Output is correct
25 Correct 3 ms 6748 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 2 ms 6820 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
29 Correct 1 ms 6748 KB Output is correct
30 Correct 956 ms 97452 KB Output is correct
31 Correct 602 ms 94244 KB Output is correct
32 Correct 803 ms 98032 KB Output is correct
33 Correct 770 ms 95996 KB Output is correct
34 Correct 748 ms 95824 KB Output is correct
35 Correct 702 ms 95988 KB Output is correct
36 Correct 662 ms 96352 KB Output is correct
37 Correct 1012 ms 101140 KB Output is correct
38 Correct 599 ms 97700 KB Output is correct
39 Correct 965 ms 97420 KB Output is correct
40 Correct 586 ms 94384 KB Output is correct
41 Correct 500 ms 94356 KB Output is correct
42 Correct 502 ms 94488 KB Output is correct
43 Correct 495 ms 94648 KB Output is correct
44 Correct 509 ms 94540 KB Output is correct
45 Correct 515 ms 95312 KB Output is correct
46 Correct 2 ms 6748 KB Output is correct
47 Correct 3 ms 6748 KB Output is correct
48 Correct 2 ms 6748 KB Output is correct
49 Correct 2 ms 6748 KB Output is correct
50 Correct 2 ms 6748 KB Output is correct
51 Correct 2 ms 6748 KB Output is correct
52 Correct 943 ms 97368 KB Output is correct
53 Correct 600 ms 94100 KB Output is correct
54 Correct 797 ms 99400 KB Output is correct
55 Correct 756 ms 95828 KB Output is correct
56 Correct 703 ms 95836 KB Output is correct
57 Correct 692 ms 96104 KB Output is correct
58 Correct 655 ms 96240 KB Output is correct
59 Correct 1006 ms 99936 KB Output is correct
60 Correct 592 ms 98040 KB Output is correct
61 Correct 951 ms 97304 KB Output is correct
62 Correct 592 ms 94260 KB Output is correct
63 Correct 2 ms 6744 KB Output is correct
64 Correct 2 ms 6748 KB Output is correct
65 Correct 2 ms 6748 KB Output is correct
66 Correct 2 ms 6748 KB Output is correct
67 Correct 2 ms 6836 KB Output is correct
68 Correct 2 ms 6744 KB Output is correct
69 Correct 2 ms 6748 KB Output is correct
70 Correct 2 ms 6748 KB Output is correct
71 Correct 2 ms 6748 KB Output is correct
72 Correct 2 ms 6748 KB Output is correct
73 Correct 2 ms 6748 KB Output is correct
74 Correct 2 ms 6748 KB Output is correct
75 Correct 2 ms 6748 KB Output is correct
76 Correct 3 ms 6748 KB Output is correct
77 Correct 2 ms 6748 KB Output is correct
78 Correct 1 ms 6744 KB Output is correct
79 Correct 1078 ms 98472 KB Output is correct
80 Correct 856 ms 96576 KB Output is correct
81 Correct 893 ms 97300 KB Output is correct
82 Correct 796 ms 94136 KB Output is correct
83 Correct 707 ms 94408 KB Output is correct
84 Correct 689 ms 94728 KB Output is correct
85 Correct 643 ms 94932 KB Output is correct
86 Correct 1020 ms 97296 KB Output is correct
87 Correct 865 ms 97672 KB Output is correct
88 Correct 954 ms 94508 KB Output is correct
89 Correct 706 ms 94032 KB Output is correct
90 Correct 577 ms 94800 KB Output is correct
91 Correct 574 ms 95592 KB Output is correct
92 Correct 2 ms 6748 KB Output is correct
93 Correct 2 ms 6748 KB Output is correct
94 Correct 3 ms 6748 KB Output is correct
95 Correct 2 ms 6748 KB Output is correct
96 Correct 2 ms 6748 KB Output is correct
97 Correct 1 ms 6748 KB Output is correct
98 Correct 1034 ms 99644 KB Output is correct
99 Correct 855 ms 95980 KB Output is correct
100 Correct 893 ms 98216 KB Output is correct
101 Correct 783 ms 95852 KB Output is correct
102 Correct 722 ms 95924 KB Output is correct
103 Correct 699 ms 95932 KB Output is correct
104 Correct 636 ms 95936 KB Output is correct
105 Correct 1116 ms 100996 KB Output is correct
106 Correct 850 ms 98060 KB Output is correct
107 Correct 998 ms 97180 KB Output is correct
108 Correct 682 ms 94236 KB Output is correct
109 Correct 576 ms 95024 KB Output is correct
110 Correct 596 ms 95716 KB Output is correct
111 Correct 2 ms 6748 KB Output is correct
112 Correct 2 ms 6748 KB Output is correct
113 Correct 2 ms 6748 KB Output is correct
114 Correct 2 ms 6748 KB Output is correct
115 Correct 3 ms 6904 KB Output is correct
116 Correct 968 ms 95576 KB Output is correct
117 Correct 771 ms 93780 KB Output is correct
118 Correct 907 ms 99808 KB Output is correct
119 Correct 825 ms 96176 KB Output is correct
120 Correct 773 ms 95756 KB Output is correct
121 Correct 846 ms 96184 KB Output is correct
122 Correct 710 ms 96112 KB Output is correct
123 Correct 1189 ms 100272 KB Output is correct
124 Correct 995 ms 96188 KB Output is correct
125 Correct 1154 ms 96748 KB Output is correct
126 Correct 812 ms 94128 KB Output is correct
127 Correct 808 ms 94544 KB Output is correct
128 Correct 810 ms 94892 KB Output is correct
129 Correct 750 ms 95592 KB Output is correct