Submission #792143

# Submission time Handle Problem Language Result Execution time Memory
792143 2023-07-24T15:53:03 Z winter0101 Sprinkler (JOI22_sprinkler) C++14
0 / 100
645 ms 85956 KB
#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define pil pair<int,long long>
#define pll pair<long long,long long>
#define eb emplace_back
#define int long long
const int maxn=2e5+9;
int n;
long long l;
vector<int>a[maxn];
long long mul[maxn][41];
int p[maxn];
long long h[maxn];
void dfs(int u,int par){
for (auto v:a[u]){
    if(v==par)continue;
    p[v]=u;
    //for1(j,0,40)mul[v][j]=1;
    dfs(v,u);
}
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("temp.INP","r",stdin);
    //freopen("temp.OUT","w",stdout);
    cin>>n>>l;
    for1(i,1,n-1){
    int u,v;
    cin>>u>>v;
    a[u].pb(v);
    a[v].pb(u);
    }
    dfs(1,0);
    for1(i,1,n)cin>>h[i];
    for1(i,1,n){
    for1(j,0,40){
    mul[i][j]=1;
    }
    }
    int q;
    cin>>q;
    for1(i,1,q){
    int t;
    cin>>t;
    if (t==1){
       int x,dis;
       long long w;
       cin>>x>>dis>>w;
       int dd=dis,u=x;
       if (dd==0){
        h[x]=(h[x]*w)%l;
        continue;
       }
       bool fl=false;
       int len=0;
       for1(j,0,dis-1){
       mul[u][dis-j]=(mul[u][dis-j]*w)%l;
       if (dis-j==len)fl=true;
       //cout<<u<<" "<<j<<'\n';
       if (p[u]!=0){
        u=p[u];
        len++;
       }
       }
       mul[u][0]=(mul[u][0]*w)%l;
       if (p[u]!=0){
        h[p[u]]=(h[p[u]]*w)%l;
       }
       if (!fl)h[x]=(h[x]*w)%l;
    }
    else {
        int x;
        cin>>x;
        long long nw=h[x];
        int u=x;
        for1(j,0,40){
        nw=(nw*mul[u][j])%l;
        //cout<<u<<" "<<mul[u][j]<<" "<<j<<'\n';
        if (p[u]!=0)u=p[u];
        else break;
        }
        cout<<nw<<'\n';
    }
    }
    //cout<<mul[2][0];
    //for1(i,1,n)cout<<h[i]<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 5028 KB Output is correct
3 Correct 2 ms 5024 KB Output is correct
4 Incorrect 3 ms 5460 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Incorrect 491 ms 83756 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Incorrect 491 ms 83756 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5024 KB Output is correct
2 Incorrect 619 ms 85288 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 645 ms 85956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 5028 KB Output is correct
3 Correct 2 ms 5024 KB Output is correct
4 Incorrect 3 ms 5460 KB Output isn't correct
5 Halted 0 ms 0 KB -