답안 #899167

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
899167 2024-01-05T14:31:47 Z alexander707070 Sprinkler (JOI22_sprinkler) C++14
0 / 100
4000 ms 93272 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];
 
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;
    
    if(dist==0)return;
    
    if(ban!=0 and dist>0){
        mult[dist-1][ban]*=power(p,mod-2);
    }
    
    query(parent[x],dist-1,x,p);
}
 
long long geth(int x,int dist){
    if(x==0 or dist>40)return 1;
 
    long long res=1;
    for(int i=dist;i<=40;i++){
        res*=mult[i][x];
        res%=mod;
    }
 
    return (res*geth(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<=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;
            cout<<( geth(s,0) )%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++){
      |                 ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 73820 KB Output is correct
2 Correct 9 ms 73816 KB Output is correct
3 Correct 9 ms 73816 KB Output is correct
4 Incorrect 15 ms 73816 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 73816 KB Output is correct
2 Incorrect 3421 ms 87684 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 73816 KB Output is correct
2 Incorrect 3421 ms 87684 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 73764 KB Output is correct
2 Execution timed out 4073 ms 93272 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 73816 KB Output is correct
2 Execution timed out 4058 ms 92916 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 73820 KB Output is correct
2 Correct 9 ms 73816 KB Output is correct
3 Correct 9 ms 73816 KB Output is correct
4 Incorrect 15 ms 73816 KB Output isn't correct
5 Halted 0 ms 0 KB -