답안 #876794

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876794 2023-11-22T10:46:41 Z simona1230 Sprinkler (JOI22_sprinkler) C++17
0 / 100
3988 ms 103912 KB
#include <bits/stdc++.h>
using namespace std;
long long n,l;
vector<long long> v[200001];
long long h[200001];
void read()
{
    cin>>n>>l;
    for(long long i=1;i<n;i++)
    {
        long long a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(long long i=1;i<=n;i++)
        cin>>h[i];
}
long long curr[200001][45];
long long q,t,x,d,w;
long long used[200001];
long long p[200001];
void dfs(long long i)
{
    used[i]=1;
    for(long long j=0;j<v[i].size();j++)
    {
        long long nb=v[i][j];
        if(!used[nb])
        {
            p[nb]=i;
            dfs(nb);
        }
    }
}
void upd(long long i,long long lvl)
{
    curr[i][lvl]*=w;
    //curr[i][lvl]%=l;
    //cout<<i<<","<<lvl<<" "<<curr[i][lvl]<<endl;
    if(i!=1&&lvl!=0)upd(p[i],lvl-1);
}
long long get(long long i,long long lvl,long long h)
{
    //cout<<i<<" - "<<lvl<<endl;
    long long here=1;
    for(long long j=lvl;j<=40;j++)
    {
        //cout<<i<<"*"<<j<<" "<<curr[i][j]<<endl;
        if(h!=0&&j!=40)here*=max((long long)1,curr[i][j]/curr[h][j+1]);
        else here*=curr[i][j];
        //here%=l;
    }
    if(i!=1&&lvl!=40)
        here*=get(p[i],lvl+1,i);
    //here%=l;
    return here;
}
void solve()
{
    for(long long i=1;i<=n;i++)
        for(long long j=0;j<=40;j++)
            curr[i][j]=1;
    dfs(1);
    cin>>q;
    for(long long i=1;i<=q;i++)
    {
        cin>>t>>x;
        if(t==1)
        {
            cin>>d>>w;
            upd(x,d);
        }
        else
        {
            cout<<(get(x,0,0)*h[x])%l<<endl;
        }
    }
}
int main()
{
    read();
    solve();
    return 0;
}

Compilation message

sprinkler.cpp: In function 'void dfs(long long int)':
sprinkler.cpp:26:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(long long j=0;j<v[i].size();j++)
      |                       ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12380 KB Output is correct
2 Correct 3 ms 12380 KB Output is correct
3 Runtime error 13 ms 24668 KB Execution killed with signal 8
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12380 KB Output is correct
2 Incorrect 3075 ms 99504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12380 KB Output is correct
2 Incorrect 3075 ms 99504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 24668 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12376 KB Output is correct
2 Correct 3988 ms 103912 KB Output is correct
3 Incorrect 1073 ms 100748 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12380 KB Output is correct
2 Correct 3 ms 12380 KB Output is correct
3 Runtime error 13 ms 24668 KB Execution killed with signal 8
4 Halted 0 ms 0 KB -