Submission #899653

# Submission time Handle Problem Language Result Execution time Memory
899653 2024-01-06T19:05:06 Z alexander707070 Sprinkler (JOI22_sprinkler) C++14
50 / 100
598 ms 94592 KB
#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define MAXN 200007
using namespace std;

int n,q,type;
long long mod,w;
int a,b,s,d;
vector<int> v[MAXN];
int parent[MAXN];

long long mult[MAXN][42];

void dfs(int x,int p){
    parent[x]=p;

    for(int i=0;i<v[x].size();i++){
        if(v[x][i]==p)continue;
        dfs(v[x][i],x);
    }
}

void query(int x,int dist,long long p){
    if(dist==0){
        mult[x][dist]*=p;
        mult[x][dist]%=mod;
        return;
    }

    mult[x][dist]*=p;
    mult[x][dist]%=mod;

    mult[x][dist-1]*=p;
    mult[x][dist-1]%=mod;

    query(parent[x],dist-1,p);
}

long long getval(int x,int dist){
    if(dist==41)return 1;

    return (mult[x][dist]*getval(parent[x],dist+1))%mod;
}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>mod;
    for(int i=1;i<=n-1;i++){
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    for(int i=0;i<=n;i++){
        for(int f=0;f<=40;f++){
            mult[i][f]=1;
        }
    }

    dfs(1,0);

    for(int i=1;i<=n;i++){
        cin>>mult[i][0];
    }

    cin>>q;
    for(int i=1;i<=q;i++){
        cin>>type;
        if(type==1){
            cin>>s>>d>>w;
            query(s,d,w);
        }else{
            cin>>s;
            cout<<getval(s,0)<<"\n";
        }
    }

    return 0;
}

Compilation message

sprinkler.cpp: In function 'void dfs(int, int)':
sprinkler.cpp:18:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7772 KB Output is correct
2 Correct 438 ms 89696 KB Output is correct
3 Correct 301 ms 90112 KB Output is correct
4 Correct 397 ms 92752 KB Output is correct
5 Correct 334 ms 89816 KB Output is correct
6 Correct 286 ms 89444 KB Output is correct
7 Correct 257 ms 90192 KB Output is correct
8 Correct 234 ms 90768 KB Output is correct
9 Correct 514 ms 94240 KB Output is correct
10 Correct 310 ms 94440 KB Output is correct
11 Correct 421 ms 89680 KB Output is correct
12 Correct 255 ms 90160 KB Output is correct
13 Correct 217 ms 90560 KB Output is correct
14 Correct 181 ms 90996 KB Output is correct
15 Correct 175 ms 90196 KB Output is correct
16 Correct 177 ms 90932 KB Output is correct
17 Correct 216 ms 91200 KB Output is correct
18 Correct 2 ms 7772 KB Output is correct
19 Correct 2 ms 7772 KB Output is correct
20 Correct 2 ms 7772 KB Output is correct
21 Correct 2 ms 7772 KB Output is correct
22 Correct 2 ms 7768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7772 KB Output is correct
2 Correct 438 ms 89696 KB Output is correct
3 Correct 301 ms 90112 KB Output is correct
4 Correct 397 ms 92752 KB Output is correct
5 Correct 334 ms 89816 KB Output is correct
6 Correct 286 ms 89444 KB Output is correct
7 Correct 257 ms 90192 KB Output is correct
8 Correct 234 ms 90768 KB Output is correct
9 Correct 514 ms 94240 KB Output is correct
10 Correct 310 ms 94440 KB Output is correct
11 Correct 421 ms 89680 KB Output is correct
12 Correct 255 ms 90160 KB Output is correct
13 Correct 217 ms 90560 KB Output is correct
14 Correct 181 ms 90996 KB Output is correct
15 Correct 175 ms 90196 KB Output is correct
16 Correct 177 ms 90932 KB Output is correct
17 Correct 216 ms 91200 KB Output is correct
18 Correct 2 ms 7772 KB Output is correct
19 Correct 2 ms 7772 KB Output is correct
20 Correct 2 ms 7772 KB Output is correct
21 Correct 2 ms 7772 KB Output is correct
22 Correct 2 ms 7768 KB Output is correct
23 Correct 2 ms 7772 KB Output is correct
24 Correct 461 ms 89620 KB Output is correct
25 Correct 275 ms 90136 KB Output is correct
26 Correct 448 ms 94592 KB Output is correct
27 Correct 368 ms 90024 KB Output is correct
28 Correct 283 ms 90424 KB Output is correct
29 Correct 297 ms 89812 KB Output is correct
30 Correct 245 ms 90660 KB Output is correct
31 Correct 540 ms 92828 KB Output is correct
32 Correct 303 ms 94468 KB Output is correct
33 Correct 488 ms 89684 KB Output is correct
34 Correct 287 ms 90104 KB Output is correct
35 Correct 2 ms 7768 KB Output is correct
36 Correct 3 ms 8028 KB Output is correct
37 Correct 3 ms 7772 KB Output is correct
38 Correct 2 ms 7772 KB Output is correct
39 Correct 3 ms 7772 KB Output is correct
40 Correct 2 ms 7772 KB Output is correct
41 Correct 2 ms 7772 KB Output is correct
42 Correct 2 ms 7772 KB Output is correct
43 Correct 2 ms 7772 KB Output is correct
44 Correct 2 ms 7772 KB Output is correct
45 Correct 3 ms 7900 KB Output is correct
46 Correct 3 ms 7772 KB Output is correct
47 Correct 2 ms 7772 KB Output is correct
48 Correct 2 ms 7772 KB Output is correct
49 Correct 2 ms 7772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7772 KB Output is correct
2 Correct 578 ms 91180 KB Output is correct
3 Correct 598 ms 91032 KB Output is correct
4 Correct 502 ms 90940 KB Output is correct
5 Correct 380 ms 87124 KB Output is correct
6 Correct 306 ms 87176 KB Output is correct
7 Correct 286 ms 87240 KB Output is correct
8 Correct 250 ms 87748 KB Output is correct
9 Correct 545 ms 90464 KB Output is correct
10 Correct 585 ms 91368 KB Output is correct
11 Correct 419 ms 86612 KB Output is correct
12 Correct 437 ms 86472 KB Output is correct
13 Correct 325 ms 88400 KB Output is correct
14 Correct 310 ms 88916 KB Output is correct
15 Correct 2 ms 7772 KB Output is correct
16 Correct 2 ms 7772 KB Output is correct
17 Correct 2 ms 7772 KB Output is correct
18 Correct 2 ms 7772 KB Output is correct
19 Correct 2 ms 7772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7892 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7772 KB Output isn't correct
2 Halted 0 ms 0 KB -