Submission #607308

# Submission time Handle Problem Language Result Execution time Memory
607308 2022-07-26T14:49:47 Z AbdelmagedNour Sprinkler (JOI22_sprinkler) C++17
100 / 100
790 ms 95980 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;
const int N=(2e5)+60,D=42;
int n,q,p[N];
long long mul[N][D],val[N],mod;
vector<vector<int>>adj;
void dfs(int v,int par){
    p[v]=par;
    for(auto&u:adj[v]){
        if(u==par)continue;
        dfs(u,v);
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>mod;
    adj.resize(n+50);
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        u--;v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(0,-1);
    int last=0;
    for(int i=n;i<=n+40;i++){
        p[last]=i;
        last=i;
    }
    for(int i=0;i<=n+40;i++)for(int j=0;j<=40;j++)mul[i][j]=1;
    for(int i=0;i<n;i++)cin>>val[i];
    cin>>q;
    while(q--){
        int type;
        cin>>type;
        if(type==1){
            long long x,d,w;
            cin>>x>>d>>w;x--;
            for(int j=d;j>=0;j--){
                mul[x][j]=(mul[x][j]*w)%mod;
                if(j>0)mul[x][j-1]=(mul[x][j-1]*w)%mod;
                x=p[x];
            }
        }else{
            long long x,ans;
            cin>>x;x--;
            ans=val[x];
            for(int j=0;j<=40;j++){
                ans=(ans*mul[x][j])%mod;
                x=p[x];
            }
            cout<<ans<<"\n";
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 328 KB Output is correct
24 Correct 1 ms 368 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 523 ms 91228 KB Output is correct
3 Correct 370 ms 91768 KB Output is correct
4 Correct 451 ms 94448 KB Output is correct
5 Correct 472 ms 91496 KB Output is correct
6 Correct 405 ms 91072 KB Output is correct
7 Correct 338 ms 91720 KB Output is correct
8 Correct 291 ms 92224 KB Output is correct
9 Correct 563 ms 95656 KB Output is correct
10 Correct 360 ms 95896 KB Output is correct
11 Correct 492 ms 91188 KB Output is correct
12 Correct 366 ms 91832 KB Output is correct
13 Correct 254 ms 92084 KB Output is correct
14 Correct 263 ms 92480 KB Output is correct
15 Correct 277 ms 91804 KB Output is correct
16 Correct 277 ms 92504 KB Output is correct
17 Correct 272 ms 92872 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 523 ms 91228 KB Output is correct
3 Correct 370 ms 91768 KB Output is correct
4 Correct 451 ms 94448 KB Output is correct
5 Correct 472 ms 91496 KB Output is correct
6 Correct 405 ms 91072 KB Output is correct
7 Correct 338 ms 91720 KB Output is correct
8 Correct 291 ms 92224 KB Output is correct
9 Correct 563 ms 95656 KB Output is correct
10 Correct 360 ms 95896 KB Output is correct
11 Correct 492 ms 91188 KB Output is correct
12 Correct 366 ms 91832 KB Output is correct
13 Correct 254 ms 92084 KB Output is correct
14 Correct 263 ms 92480 KB Output is correct
15 Correct 277 ms 91804 KB Output is correct
16 Correct 277 ms 92504 KB Output is correct
17 Correct 272 ms 92872 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 505 ms 91204 KB Output is correct
25 Correct 376 ms 91952 KB Output is correct
26 Correct 519 ms 95880 KB Output is correct
27 Correct 456 ms 91456 KB Output is correct
28 Correct 383 ms 91568 KB Output is correct
29 Correct 367 ms 91348 KB Output is correct
30 Correct 365 ms 92352 KB Output is correct
31 Correct 656 ms 94372 KB Output is correct
32 Correct 454 ms 95980 KB Output is correct
33 Correct 524 ms 91172 KB Output is correct
34 Correct 421 ms 91752 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 324 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 574 ms 92796 KB Output is correct
3 Correct 770 ms 92472 KB Output is correct
4 Correct 563 ms 92116 KB Output is correct
5 Correct 465 ms 88524 KB Output is correct
6 Correct 404 ms 88776 KB Output is correct
7 Correct 369 ms 88780 KB Output is correct
8 Correct 296 ms 89364 KB Output is correct
9 Correct 574 ms 91460 KB Output is correct
10 Correct 715 ms 92936 KB Output is correct
11 Correct 542 ms 88248 KB Output is correct
12 Correct 626 ms 89000 KB Output is correct
13 Correct 417 ms 89896 KB Output is correct
14 Correct 397 ms 90404 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 578 ms 93904 KB Output is correct
3 Correct 662 ms 91684 KB Output is correct
4 Correct 529 ms 92784 KB Output is correct
5 Correct 531 ms 90104 KB Output is correct
6 Correct 403 ms 90336 KB Output is correct
7 Correct 394 ms 90052 KB Output is correct
8 Correct 360 ms 90512 KB Output is correct
9 Correct 619 ms 95192 KB Output is correct
10 Correct 740 ms 93752 KB Output is correct
11 Correct 562 ms 90852 KB Output is correct
12 Correct 656 ms 89396 KB Output is correct
13 Correct 401 ms 90032 KB Output is correct
14 Correct 448 ms 90632 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 328 KB Output is correct
24 Correct 1 ms 368 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 523 ms 91228 KB Output is correct
31 Correct 370 ms 91768 KB Output is correct
32 Correct 451 ms 94448 KB Output is correct
33 Correct 472 ms 91496 KB Output is correct
34 Correct 405 ms 91072 KB Output is correct
35 Correct 338 ms 91720 KB Output is correct
36 Correct 291 ms 92224 KB Output is correct
37 Correct 563 ms 95656 KB Output is correct
38 Correct 360 ms 95896 KB Output is correct
39 Correct 492 ms 91188 KB Output is correct
40 Correct 366 ms 91832 KB Output is correct
41 Correct 254 ms 92084 KB Output is correct
42 Correct 263 ms 92480 KB Output is correct
43 Correct 277 ms 91804 KB Output is correct
44 Correct 277 ms 92504 KB Output is correct
45 Correct 272 ms 92872 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 505 ms 91204 KB Output is correct
53 Correct 376 ms 91952 KB Output is correct
54 Correct 519 ms 95880 KB Output is correct
55 Correct 456 ms 91456 KB Output is correct
56 Correct 383 ms 91568 KB Output is correct
57 Correct 367 ms 91348 KB Output is correct
58 Correct 365 ms 92352 KB Output is correct
59 Correct 656 ms 94372 KB Output is correct
60 Correct 454 ms 95980 KB Output is correct
61 Correct 524 ms 91172 KB Output is correct
62 Correct 421 ms 91752 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 336 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 1 ms 324 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 574 ms 92796 KB Output is correct
80 Correct 770 ms 92472 KB Output is correct
81 Correct 563 ms 92116 KB Output is correct
82 Correct 465 ms 88524 KB Output is correct
83 Correct 404 ms 88776 KB Output is correct
84 Correct 369 ms 88780 KB Output is correct
85 Correct 296 ms 89364 KB Output is correct
86 Correct 574 ms 91460 KB Output is correct
87 Correct 715 ms 92936 KB Output is correct
88 Correct 542 ms 88248 KB Output is correct
89 Correct 626 ms 89000 KB Output is correct
90 Correct 417 ms 89896 KB Output is correct
91 Correct 397 ms 90404 KB Output is correct
92 Correct 1 ms 340 KB Output is correct
93 Correct 1 ms 340 KB Output is correct
94 Correct 1 ms 340 KB Output is correct
95 Correct 1 ms 332 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 1 ms 328 KB Output is correct
98 Correct 578 ms 93904 KB Output is correct
99 Correct 662 ms 91684 KB Output is correct
100 Correct 529 ms 92784 KB Output is correct
101 Correct 531 ms 90104 KB Output is correct
102 Correct 403 ms 90336 KB Output is correct
103 Correct 394 ms 90052 KB Output is correct
104 Correct 360 ms 90512 KB Output is correct
105 Correct 619 ms 95192 KB Output is correct
106 Correct 740 ms 93752 KB Output is correct
107 Correct 562 ms 90852 KB Output is correct
108 Correct 656 ms 89396 KB Output is correct
109 Correct 401 ms 90032 KB Output is correct
110 Correct 448 ms 90632 KB Output is correct
111 Correct 1 ms 340 KB Output is correct
112 Correct 1 ms 340 KB Output is correct
113 Correct 1 ms 340 KB Output is correct
114 Correct 1 ms 340 KB Output is correct
115 Correct 1 ms 372 KB Output is correct
116 Correct 596 ms 89392 KB Output is correct
117 Correct 650 ms 91844 KB Output is correct
118 Correct 605 ms 95820 KB Output is correct
119 Correct 510 ms 91532 KB Output is correct
120 Correct 410 ms 91104 KB Output is correct
121 Correct 480 ms 91900 KB Output is correct
122 Correct 354 ms 92284 KB Output is correct
123 Correct 576 ms 94944 KB Output is correct
124 Correct 790 ms 94308 KB Output is correct
125 Correct 557 ms 90536 KB Output is correct
126 Correct 609 ms 91704 KB Output is correct
127 Correct 672 ms 92292 KB Output is correct
128 Correct 548 ms 92940 KB Output is correct
129 Correct 558 ms 93328 KB Output is correct