Submission #899173

# Submission time Handle Problem Language Result Execution time Memory
899173 2024-01-05T14:39:23 Z alexander707070 Sprinkler (JOI22_sprinkler) C++14
0 / 100
11 ms 74072 KB
#include<bits/stdc++.h>
#define MAXN 200007
using namespace std;
 
int n,q,type;
long long mod,w;
int a,b,s,d;
vector<int> v[MAXN];
int num[MAXN],tt,from[MAXN],to[MAXN],parent[MAXN];
 
long long mult[42][MAXN],delt[42][MAXN];
 
void dfs(int x,int p){
    from[x]=n; to[x]=0;
    parent[x]=p;
 
    for(int i=0;i<v[x].size();i++){
        if(v[x][i]==p)continue;
 
        tt++; num[v[x][i]]=tt;
        from[x]=min(from[x],tt);
        to[x]=max(to[x],tt);
    }
 
    for(int i=0;i<v[x].size();i++){
        if(v[x][i]==p)continue;
        dfs(v[x][i],x);
    }
}
 
long long power(long long a,long long b){
    if(b==0)return 1;
    if(b==1)return a;
    if(b==2)return (a*a)%mod;
    if(b%2==0)return power(power(a,b/2),2);
    return (power(power(a,b/2),2)*a)%mod;
}
 
void query(int x,int dist,int ban,long long p){
    if(x==0)return;
    mult[dist][x]*=p;
    mult[dist][x]%=mod;
    
    if(dist==0)return;
    
    if(ban!=0 and dist>0){
        delt[dist-1][ban]*=p;
        delt[dist-1][ban]%=mod;
    }
    
    query(parent[x],dist-1,x,p);
}
 
pair<long long,long long> geth(int x,int dist){
    if(x==0 or dist>40)return {1,1};
 
    long long res=1,res2=1;
    for(int i=dist;i<=40;i++){
        res*=mult[i][x];
        res2*=delt[i][x];
        res%=mod; res2%=mod;
    }
    
    pair<long long,long long> w=geth(parent[x],dist+1);
    return {(w.first*res)%mod,(w.second*res2)%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<=40;i++){
        for(int f=1;f<=n;f++){
            mult[i][f]=1;
        }
    }
 
    num[1]=1; tt=1;
    dfs(1,0);
 
    for(int i=1;i<=n;i++){
        cin>>mult[0][i];
    }
 
    cin>>q;
    for(int i=1;i<=q;i++){
        cin>>type;
        if(type==1){
            cin>>s>>d>>w;
            query(s,d,0,w);
        }else{
            cin>>s;
            pair<long long,long long> w=geth(s,0);
            cout<<(w.first*power(w.second,mod-2))%mod<<"\n";
        }
    }
 
    return 0;
}

Compilation message

sprinkler.cpp: In function 'void dfs(int, int)':
sprinkler.cpp:17:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
sprinkler.cpp:25:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 74072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 73820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 73820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 73820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 73884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 74072 KB Output isn't correct
2 Halted 0 ms 0 KB -