Submission #991581

# Submission time Handle Problem Language Result Execution time Memory
991581 2024-06-02T14:09:17 Z snpmrnhlol Sprinkler (JOI22_sprinkler) C++17
38 / 100
427 ms 60756 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5;
const int D = 40;
vector <int> e[N];
vector <int> path;
int pr[N];
int bonus[N][D];
int v[N];
void dfs(int node, int p){
    pr[node] = p;
    for(auto i:e[node]){
        if(i == p)continue;
        dfs(i, node);
    }

}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,mod;
    cin>>n>>mod;
    for(int i = 0;i < n - 1;i++){
        int u,w;
        cin>>u>>w;
        e[u - 1].push_back(w - 1);
        e[w - 1].push_back(u - 1);
    }
    for(int i = 0;i < n;i++){
        cin>>v[i];
        for(int j = 0;j <= D;j++){
            bonus[i][j] = 1;
        }
    }
    dfs(0, -1);
    int q;
    cin>>q;
    for(int i = 0;i < q;i++){
        int tip;
        cin>>tip;
        ///limit:40
        if(tip == 1){
            int x,d,w;
            cin>>x>>d>>w;
            x--;
            int cnt = 0;
            for(int j = x;j != -1 && cnt <= d;j = pr[j]){
                bonus[j][d - cnt] = 1ll*bonus[j][d - cnt]*w%mod;
                //cout<<"update:"<<j<<' '<<d - cnt<<' '<<w<<'\n';
                cnt++;
            }
        }else{
            int x;
            cin>>x;
            x--;
            int ans = v[x];
            for(int j = 0;j < D && x != -1;j++){
                if(x == 0){
                    for(int k = j;k < D;k++){
                        ans = 1ll*ans*bonus[x][k]%mod;
                    }
                }else{
                    ans = 1ll*ans*bonus[x][j]%mod;
                    if(j != D - 1){
                        ans = 1ll*ans*bonus[x][j + 1]%mod;
                    }
                }
                x = pr[x];
            }
            cout<<ans<<'\n';
        }
    }
    return 0;
}

Compilation message

sprinkler.cpp: In function 'int main()':
sprinkler.cpp:32:25: warning: iteration 40 invokes undefined behavior [-Waggressive-loop-optimizations]
   32 |             bonus[i][j] = 1;
      |             ~~~~~~~~~~~~^~~
sprinkler.cpp:31:25: note: within this loop
   31 |         for(int j = 0;j <= D;j++){
      |                       ~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 9052 KB Output is correct
2 Correct 1 ms 9052 KB Output is correct
3 Correct 1 ms 9052 KB Output is correct
4 Incorrect 3 ms 9052 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 9052 KB Output is correct
2 Correct 333 ms 56096 KB Output is correct
3 Correct 206 ms 56660 KB Output is correct
4 Correct 285 ms 59220 KB Output is correct
5 Correct 282 ms 56340 KB Output is correct
6 Correct 222 ms 55888 KB Output is correct
7 Correct 223 ms 56660 KB Output is correct
8 Correct 187 ms 57032 KB Output is correct
9 Correct 411 ms 60480 KB Output is correct
10 Correct 207 ms 60756 KB Output is correct
11 Correct 381 ms 56148 KB Output is correct
12 Correct 195 ms 56444 KB Output is correct
13 Correct 162 ms 56772 KB Output is correct
14 Correct 151 ms 57284 KB Output is correct
15 Correct 144 ms 56624 KB Output is correct
16 Correct 176 ms 57172 KB Output is correct
17 Correct 164 ms 57688 KB Output is correct
18 Correct 2 ms 9052 KB Output is correct
19 Correct 2 ms 9052 KB Output is correct
20 Correct 2 ms 9128 KB Output is correct
21 Correct 2 ms 9052 KB Output is correct
22 Correct 2 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 9052 KB Output is correct
2 Correct 333 ms 56096 KB Output is correct
3 Correct 206 ms 56660 KB Output is correct
4 Correct 285 ms 59220 KB Output is correct
5 Correct 282 ms 56340 KB Output is correct
6 Correct 222 ms 55888 KB Output is correct
7 Correct 223 ms 56660 KB Output is correct
8 Correct 187 ms 57032 KB Output is correct
9 Correct 411 ms 60480 KB Output is correct
10 Correct 207 ms 60756 KB Output is correct
11 Correct 381 ms 56148 KB Output is correct
12 Correct 195 ms 56444 KB Output is correct
13 Correct 162 ms 56772 KB Output is correct
14 Correct 151 ms 57284 KB Output is correct
15 Correct 144 ms 56624 KB Output is correct
16 Correct 176 ms 57172 KB Output is correct
17 Correct 164 ms 57688 KB Output is correct
18 Correct 2 ms 9052 KB Output is correct
19 Correct 2 ms 9052 KB Output is correct
20 Correct 2 ms 9128 KB Output is correct
21 Correct 2 ms 9052 KB Output is correct
22 Correct 2 ms 9052 KB Output is correct
23 Correct 1 ms 9052 KB Output is correct
24 Correct 347 ms 56124 KB Output is correct
25 Correct 202 ms 56660 KB Output is correct
26 Correct 312 ms 60756 KB Output is correct
27 Correct 288 ms 56212 KB Output is correct
28 Correct 228 ms 56512 KB Output is correct
29 Correct 228 ms 56112 KB Output is correct
30 Correct 185 ms 57232 KB Output is correct
31 Correct 392 ms 59220 KB Output is correct
32 Correct 228 ms 60756 KB Output is correct
33 Correct 376 ms 55944 KB Output is correct
34 Correct 196 ms 56408 KB Output is correct
35 Correct 2 ms 9052 KB Output is correct
36 Correct 1 ms 9052 KB Output is correct
37 Correct 2 ms 9052 KB Output is correct
38 Correct 2 ms 9052 KB Output is correct
39 Correct 2 ms 9052 KB Output is correct
40 Correct 2 ms 9052 KB Output is correct
41 Correct 2 ms 9052 KB Output is correct
42 Correct 2 ms 9052 KB Output is correct
43 Correct 2 ms 9052 KB Output is correct
44 Correct 2 ms 9092 KB Output is correct
45 Correct 2 ms 9052 KB Output is correct
46 Correct 2 ms 9052 KB Output is correct
47 Correct 1 ms 9052 KB Output is correct
48 Correct 2 ms 9128 KB Output is correct
49 Correct 2 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 9052 KB Output is correct
2 Incorrect 427 ms 57788 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 9052 KB Output is correct
2 Incorrect 426 ms 58704 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 9052 KB Output is correct
2 Correct 1 ms 9052 KB Output is correct
3 Correct 1 ms 9052 KB Output is correct
4 Incorrect 3 ms 9052 KB Output isn't correct
5 Halted 0 ms 0 KB -