Submission #998425

# Submission time Handle Problem Language Result Execution time Memory
998425 2024-06-14T01:17:18 Z jampm Sprinkler (JOI22_sprinkler) C++17
0 / 100
1816 ms 208004 KB
//Emmanuel B
//Sprinker




#include <bits/stdc++.h>
using namespace std;
using lli=long long int;
#define pb push_back
#define deb(x) cout<<#x<<": "<<x<<endl;
#define deb2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;


void dfs(lli n, lli par, vector<lli> &parent, vector<vector<lli>> &adj, vector<vector<lli>> &sons){
    parent[n]=par;
    for(lli x: adj[n]){
        if(x==par) continue;
        sons[n].pb(x);
        dfs(x,n,parent,adj,sons);
    }
}
lli L;
void update(lli n, lli p, vector<vector<lli>> &adj, lli c, vector<lli> &values, lli &w){
    if(c<0) return;
    values[n]*=w;
    values[n]%=L;
    if(c==0) return;
    for(lli x: adj[n]){
        if(x==p) continue;
        update(x,n,adj,c-1, values, w);
    }
}

int main(){
    lli N;
    cin>>N>>L;
    vector<vector<lli>> adj (N+5);
    for(lli i=0; i<N-1; ++i){
        lli a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    vector<lli> parent (N+5);
    vector<vector<lli>> sons (N+5);
    vector<lli> mult1 (N+5,1);
    vector<lli> mult2 (N+5,1);
    dfs(1,0,parent,adj,sons);
    vector<lli> values (N+5);
    vector<vector<lli>> resolver (N+5, vector<lli> (44,1));
    vector<vector<lli>> numof0s (N+5, vector<lli> (44,0));
    for(lli i=1; i<=N; ++i){
        cin>>values[i];
    }
    lli Q;
    cin>>Q;
    while(Q--){
        lli type;
        cin>>type;
        if(type==1){
            lli x,d,w;
            cin>>x>>d>>w;
            while(d>=0 && x!=0){
      //          deb(d);
     //           deb(x);
            for(lli i=0;  i<=d; ++i){
                lli val=resolver[x][i]*w;
        //        deb(val);
                if(val==0){
                    resolver[x][i]=0;
                    continue;
                }
                while(val%L==0){
                    numof0s[x][i]++;
                    val/=L;
                }
                resolver[x][i]=val;
                resolver[x][i]%=L;
            }
            d--;
            x=parent[x];
            }
        }
        else{
            lli x;
            cin>>x;
            lli ans=values[x]*resolver[x][0];
            ans%=L;
            lli act=parent[x];
            lli cont=1;

            while(act!=0 && cont+1<resolver.size()){
                
                if(numof0s[act][cont]>numof0s[x][cont+1]){
                    ans=0;
                    break;
                }
                if(resolver[x][cont+1]==0){
                    ans=0;
                    break;
                }
                lli val=resolver[act][cont]/resolver[x][cont+1];
                
                ans*=val;
                x=act;
                act=parent[act];
                cont++;
            }
            cout<<ans<<endl;
        }
    }
    
}

Compilation message

sprinkler.cpp: In function 'int main()':
sprinkler.cpp:93:35: warning: comparison of integer expressions of different signedness: 'lli' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |             while(act!=0 && cont+1<resolver.size()){
      |                             ~~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1292 ms 208004 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1816 ms 200796 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -