Submission #898582

# Submission time Handle Problem Language Result Execution time Memory
898582 2024-01-04T22:40:33 Z alexander707070 Sprinkler (JOI22_sprinkler) C++14
3 / 100
38 ms 96368 KB
#include<bits/stdc++.h>
#define MAXN 200000
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 tree[42][4*MAXN],val[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);
    }
}

void update(int id,int v,int l,int r,int ll,int rr,long long val){
    if(ll>rr)return;
    if(l==ll and r==rr){
        tree[id][v]*=val; tree[id][v]%=mod;
    }else{
        int tt=(l+r)/2;
        update(id,2*v,l,tt,ll,min(tt,rr),val);
        update(id,2*v+1,tt+1,r,max(tt+1,ll),rr,val);
    }
}

long long getval(int id,int v,int l,int r,int pos){
    if(l==r)return tree[id][v];
    
    int tt=(l+r)/2;
    if(pos<=tt)return (getval(id,2*v,l,tt,pos) * tree[id][v])%mod;
    return (getval(id,2*v+1,tt+1,r,pos) * tree[id][v])%mod;
}

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

    if(ban>=from[x] and ban<=to[x]){
        update(dist-1,1,1,n,from[x],ban-1,mult);
        update(dist-1,1,1,n,ban+1,to[x],mult);
    }else{
        update(dist-1,1,1,n,from[x],to[x],mult);
    }

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

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*=getval(i,1,1,n,num[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<=4*n;f++){
            tree[i][f]=1;
        }
    }

    num[1]=1; tt=1;
    dfs(1,0);

    for(int i=1;i<=n;i++){
        cin>>val[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<<( val[s]*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++){
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 94032 KB Output is correct
2 Correct 11 ms 94044 KB Output is correct
3 Correct 10 ms 94080 KB Output is correct
4 Correct 38 ms 96368 KB Output is correct
5 Correct 37 ms 96088 KB Output is correct
6 Correct 26 ms 96348 KB Output is correct
7 Correct 21 ms 96092 KB Output is correct
8 Correct 15 ms 96296 KB Output is correct
9 Correct 12 ms 94148 KB Output is correct
10 Correct 13 ms 94044 KB Output is correct
11 Correct 11 ms 94044 KB Output is correct
12 Correct 13 ms 94040 KB Output is correct
13 Correct 13 ms 94044 KB Output is correct
14 Correct 11 ms 94044 KB Output is correct
15 Correct 11 ms 94084 KB Output is correct
16 Correct 12 ms 94132 KB Output is correct
17 Correct 13 ms 94172 KB Output is correct
18 Correct 13 ms 94104 KB Output is correct
19 Correct 12 ms 94040 KB Output is correct
20 Correct 11 ms 94044 KB Output is correct
21 Correct 12 ms 94048 KB Output is correct
22 Correct 15 ms 94128 KB Output is correct
23 Correct 13 ms 94044 KB Output is correct
24 Correct 11 ms 94044 KB Output is correct
25 Correct 13 ms 94104 KB Output is correct
26 Correct 12 ms 94040 KB Output is correct
27 Correct 13 ms 94044 KB Output is correct
28 Correct 12 ms 94180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 94044 KB Output is correct
2 Runtime error 12 ms 12724 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 94044 KB Output is correct
2 Runtime error 12 ms 12724 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 94040 KB Output is correct
2 Runtime error 19 ms 16220 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 94044 KB Output is correct
2 Runtime error 37 ms 22564 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 94032 KB Output is correct
2 Correct 11 ms 94044 KB Output is correct
3 Correct 10 ms 94080 KB Output is correct
4 Correct 38 ms 96368 KB Output is correct
5 Correct 37 ms 96088 KB Output is correct
6 Correct 26 ms 96348 KB Output is correct
7 Correct 21 ms 96092 KB Output is correct
8 Correct 15 ms 96296 KB Output is correct
9 Correct 12 ms 94148 KB Output is correct
10 Correct 13 ms 94044 KB Output is correct
11 Correct 11 ms 94044 KB Output is correct
12 Correct 13 ms 94040 KB Output is correct
13 Correct 13 ms 94044 KB Output is correct
14 Correct 11 ms 94044 KB Output is correct
15 Correct 11 ms 94084 KB Output is correct
16 Correct 12 ms 94132 KB Output is correct
17 Correct 13 ms 94172 KB Output is correct
18 Correct 13 ms 94104 KB Output is correct
19 Correct 12 ms 94040 KB Output is correct
20 Correct 11 ms 94044 KB Output is correct
21 Correct 12 ms 94048 KB Output is correct
22 Correct 15 ms 94128 KB Output is correct
23 Correct 13 ms 94044 KB Output is correct
24 Correct 11 ms 94044 KB Output is correct
25 Correct 13 ms 94104 KB Output is correct
26 Correct 12 ms 94040 KB Output is correct
27 Correct 13 ms 94044 KB Output is correct
28 Correct 12 ms 94180 KB Output is correct
29 Correct 11 ms 94044 KB Output is correct
30 Runtime error 12 ms 12724 KB Execution killed with signal 11
31 Halted 0 ms 0 KB -