답안 #561323

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
561323 2022-05-12T16:12:42 Z hibiki Sprinkler (JOI22_sprinkler) C++11
12 / 100
957 ms 87288 KB
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define f first
#define s second

int n,q,fa[200005];
long long mod,h[200005];
long long mul[200005][42];
vector<int> v[200005];

void dfs(int nw,int pre)
{
    fa[nw] = pre;
    for(auto go: v[nw])
    {
        if(go == pre) continue;

        dfs(go,nw);
    }
}

void update(int nw,int left,long long w)
{
    if(fa[nw] == -1)
    {
        for(int i = 0; i < min(left + 1,42); i++)
        mul[nw][i] *= w %= mod;

        return ;
    }

    mul[nw][left] *= w %= mod;

    if(left == 0)
        return ;


    update(fa[nw],left - 1,w);
}

long long query(int nw,int dis)
{
    long long ret = 1;

    ret *= mul[nw][dis] %= mod;

    if(dis == 41 || fa[nw] == -1)
        return ret;

    ret *= mul[nw][dis + 1] %= mod;

    long long pre = query(fa[nw],dis + 1);

    ret *= pre %= mod;

    return ret;
}

int main()
{
    // initialize
    for(int i = 0; i < 200005; i++)
        for(int j = 0; j < 42; j++)
            mul[i][j] = 1ll;

    // input
    scanf("%d %lld",&n,&mod);
    for(int i = 0; i < n - 1; i++)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        v[a].pb(b);
        v[b].pb(a);
    }
    for(int i = 1; i <= n; i++)
        scanf("%d",&h[i]);

    dfs(1,-1);

    scanf("%d",&q);
    for(int i = 0; i < q; i++)
    {
        int t;
        scanf("%d",&t);

        if(t == 1)
        {
            int x,d;
            long long w;
            scanf("%d %d %lld",&x,&d,&w);
            update(x,d,w);
        }
        else
        {
            int x;
            scanf("%d",&x);
            long long ans = h[x] * query(x,0);
            ans %= mod;
            printf("%lld\n",ans);
        }
    }

    return 0;
}

Compilation message

sprinkler.cpp: In function 'int main()':
sprinkler.cpp:78:17: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   78 |         scanf("%d",&h[i]);
      |                ~^  ~~~~~
      |                 |  |
      |                 |  long long int*
      |                 int*
      |                %lld
sprinkler.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |     scanf("%d %lld",&n,&mod);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
sprinkler.cpp:73:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         scanf("%d %d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~
sprinkler.cpp:78:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         scanf("%d",&h[i]);
      |         ~~~~~^~~~~~~~~~~~
sprinkler.cpp:82:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
sprinkler.cpp:86:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         scanf("%d",&t);
      |         ~~~~~^~~~~~~~~
sprinkler.cpp:92:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |             scanf("%d %d %lld",&x,&d,&w);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:98:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |             scanf("%d",&x);
      |             ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 70728 KB Output is correct
2 Correct 32 ms 70644 KB Output is correct
3 Correct 38 ms 70636 KB Output is correct
4 Incorrect 36 ms 70732 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 70732 KB Output is correct
2 Incorrect 736 ms 83160 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 70732 KB Output is correct
2 Incorrect 736 ms 83160 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 70764 KB Output is correct
2 Correct 943 ms 85316 KB Output is correct
3 Correct 753 ms 83384 KB Output is correct
4 Correct 740 ms 87128 KB Output is correct
5 Correct 672 ms 83380 KB Output is correct
6 Correct 478 ms 83556 KB Output is correct
7 Correct 467 ms 83904 KB Output is correct
8 Correct 341 ms 84260 KB Output is correct
9 Correct 883 ms 87288 KB Output is correct
10 Correct 783 ms 87260 KB Output is correct
11 Correct 797 ms 83864 KB Output is correct
12 Correct 659 ms 83048 KB Output is correct
13 Correct 459 ms 83992 KB Output is correct
14 Correct 466 ms 83964 KB Output is correct
15 Correct 40 ms 70732 KB Output is correct
16 Correct 33 ms 70652 KB Output is correct
17 Correct 31 ms 70696 KB Output is correct
18 Correct 41 ms 70736 KB Output is correct
19 Correct 35 ms 70732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 70688 KB Output is correct
2 Correct 957 ms 86296 KB Output is correct
3 Incorrect 712 ms 82628 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 70728 KB Output is correct
2 Correct 32 ms 70644 KB Output is correct
3 Correct 38 ms 70636 KB Output is correct
4 Incorrect 36 ms 70732 KB Output isn't correct
5 Halted 0 ms 0 KB -