답안 #544574

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544574 2022-04-02T11:20:45 Z Rafi22 Sprinkler (JOI22_sprinkler) C++14
100 / 100
619 ms 89048 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;

const int N=200107,D=42;

vector<int>G[N];
int o[N];

void dfs(int v)
{
    for(auto u:G[v])
    {
        if(u==o[v]) continue;
        o[u]=v;
        dfs(u);
    }
}

ll T[N][D];
ll h[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,q,a,b;
    cin>>n>>mod;
    for(int i=1;i<n;i++)
    {
        cin>>a>>b;
        G[a].pb(b);
        G[b].pb(a);
    }
    dfs(1);
    for(int i=n+1;i<n+41;i++) o[i]=i+1;
    o[1]=n+1;
    for(int i=1;i<=n;i++) cin>>h[i];
    for(int i=1;i<=n+41;i++)
    {
        for(int j=0;j<=41;j++) T[i][j]=1;
    }
    cin>>q;
    while(q--)
    {
        int t;
        cin>>t;
        if(t==1)
        {
            int x,d,w;
            cin>>x>>d>>w;
            for(int i=0;i<=d;i++)
            {
                T[x][d-i]=T[x][d-i]*w%mod;
                x=o[x];
            }
        }
        else
        {
            int x;
            cin>>x;
            ll ans=h[x];
            for(int i=0;i<41;i++)
            {
                ans=ans*T[x][i]%mod;
                ans=ans*T[x][i+1]%mod;
                x=o[x];
            }
            cout<<ans<<endl;
        }
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5332 KB Output is correct
5 Correct 4 ms 5332 KB Output is correct
6 Correct 4 ms 5440 KB Output is correct
7 Correct 4 ms 5332 KB Output is correct
8 Correct 4 ms 5436 KB Output is correct
9 Correct 3 ms 5060 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5064 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 4 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 4 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 504 ms 82992 KB Output is correct
3 Correct 360 ms 79748 KB Output is correct
4 Correct 474 ms 85324 KB Output is correct
5 Correct 420 ms 81444 KB Output is correct
6 Correct 399 ms 82124 KB Output is correct
7 Correct 385 ms 81632 KB Output is correct
8 Correct 329 ms 82072 KB Output is correct
9 Correct 576 ms 89048 KB Output is correct
10 Correct 353 ms 85232 KB Output is correct
11 Correct 513 ms 83024 KB Output is correct
12 Correct 341 ms 79936 KB Output is correct
13 Correct 249 ms 80404 KB Output is correct
14 Correct 258 ms 80500 KB Output is correct
15 Correct 241 ms 80492 KB Output is correct
16 Correct 252 ms 80500 KB Output is correct
17 Correct 261 ms 81004 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 504 ms 82992 KB Output is correct
3 Correct 360 ms 79748 KB Output is correct
4 Correct 474 ms 85324 KB Output is correct
5 Correct 420 ms 81444 KB Output is correct
6 Correct 399 ms 82124 KB Output is correct
7 Correct 385 ms 81632 KB Output is correct
8 Correct 329 ms 82072 KB Output is correct
9 Correct 576 ms 89048 KB Output is correct
10 Correct 353 ms 85232 KB Output is correct
11 Correct 513 ms 83024 KB Output is correct
12 Correct 341 ms 79936 KB Output is correct
13 Correct 249 ms 80404 KB Output is correct
14 Correct 258 ms 80500 KB Output is correct
15 Correct 241 ms 80492 KB Output is correct
16 Correct 252 ms 80500 KB Output is correct
17 Correct 261 ms 81004 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 4 ms 4948 KB Output is correct
24 Correct 512 ms 83020 KB Output is correct
25 Correct 348 ms 79820 KB Output is correct
26 Correct 485 ms 87180 KB Output is correct
27 Correct 436 ms 81392 KB Output is correct
28 Correct 399 ms 81564 KB Output is correct
29 Correct 379 ms 81540 KB Output is correct
30 Correct 331 ms 82216 KB Output is correct
31 Correct 603 ms 87072 KB Output is correct
32 Correct 368 ms 85268 KB Output is correct
33 Correct 510 ms 83044 KB Output is correct
34 Correct 351 ms 79864 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 3 ms 4948 KB Output is correct
41 Correct 3 ms 4948 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 3 ms 4948 KB Output is correct
44 Correct 3 ms 4948 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5024 KB Output is correct
2 Correct 591 ms 86176 KB Output is correct
3 Correct 564 ms 83960 KB Output is correct
4 Correct 565 ms 84736 KB Output is correct
5 Correct 475 ms 79760 KB Output is correct
6 Correct 371 ms 80000 KB Output is correct
7 Correct 379 ms 80220 KB Output is correct
8 Correct 327 ms 80560 KB Output is correct
9 Correct 595 ms 84628 KB Output is correct
10 Correct 560 ms 84896 KB Output is correct
11 Correct 541 ms 80228 KB Output is correct
12 Correct 507 ms 79552 KB Output is correct
13 Correct 342 ms 80332 KB Output is correct
14 Correct 348 ms 80972 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4952 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4960 KB Output is correct
2 Correct 619 ms 86836 KB Output is correct
3 Correct 572 ms 82892 KB Output is correct
4 Correct 514 ms 84948 KB Output is correct
5 Correct 467 ms 81444 KB Output is correct
6 Correct 422 ms 81620 KB Output is correct
7 Correct 418 ms 81408 KB Output is correct
8 Correct 383 ms 81952 KB Output is correct
9 Correct 595 ms 88448 KB Output is correct
10 Correct 565 ms 85376 KB Output is correct
11 Correct 538 ms 82872 KB Output is correct
12 Correct 541 ms 79908 KB Output is correct
13 Correct 355 ms 80556 KB Output is correct
14 Correct 364 ms 80912 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5332 KB Output is correct
5 Correct 4 ms 5332 KB Output is correct
6 Correct 4 ms 5440 KB Output is correct
7 Correct 4 ms 5332 KB Output is correct
8 Correct 4 ms 5436 KB Output is correct
9 Correct 3 ms 5060 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5064 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 4 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 4 ms 4948 KB Output is correct
29 Correct 2 ms 4948 KB Output is correct
30 Correct 504 ms 82992 KB Output is correct
31 Correct 360 ms 79748 KB Output is correct
32 Correct 474 ms 85324 KB Output is correct
33 Correct 420 ms 81444 KB Output is correct
34 Correct 399 ms 82124 KB Output is correct
35 Correct 385 ms 81632 KB Output is correct
36 Correct 329 ms 82072 KB Output is correct
37 Correct 576 ms 89048 KB Output is correct
38 Correct 353 ms 85232 KB Output is correct
39 Correct 513 ms 83024 KB Output is correct
40 Correct 341 ms 79936 KB Output is correct
41 Correct 249 ms 80404 KB Output is correct
42 Correct 258 ms 80500 KB Output is correct
43 Correct 241 ms 80492 KB Output is correct
44 Correct 252 ms 80500 KB Output is correct
45 Correct 261 ms 81004 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 4 ms 4948 KB Output is correct
52 Correct 512 ms 83020 KB Output is correct
53 Correct 348 ms 79820 KB Output is correct
54 Correct 485 ms 87180 KB Output is correct
55 Correct 436 ms 81392 KB Output is correct
56 Correct 399 ms 81564 KB Output is correct
57 Correct 379 ms 81540 KB Output is correct
58 Correct 331 ms 82216 KB Output is correct
59 Correct 603 ms 87072 KB Output is correct
60 Correct 368 ms 85268 KB Output is correct
61 Correct 510 ms 83044 KB Output is correct
62 Correct 351 ms 79864 KB Output is correct
63 Correct 3 ms 4948 KB Output is correct
64 Correct 3 ms 4948 KB Output is correct
65 Correct 3 ms 4948 KB Output is correct
66 Correct 3 ms 4948 KB Output is correct
67 Correct 3 ms 4948 KB Output is correct
68 Correct 3 ms 4948 KB Output is correct
69 Correct 3 ms 4948 KB Output is correct
70 Correct 3 ms 4948 KB Output is correct
71 Correct 3 ms 4948 KB Output is correct
72 Correct 3 ms 4948 KB Output is correct
73 Correct 3 ms 4948 KB Output is correct
74 Correct 3 ms 4948 KB Output is correct
75 Correct 3 ms 4948 KB Output is correct
76 Correct 3 ms 4948 KB Output is correct
77 Correct 3 ms 4948 KB Output is correct
78 Correct 3 ms 5024 KB Output is correct
79 Correct 591 ms 86176 KB Output is correct
80 Correct 564 ms 83960 KB Output is correct
81 Correct 565 ms 84736 KB Output is correct
82 Correct 475 ms 79760 KB Output is correct
83 Correct 371 ms 80000 KB Output is correct
84 Correct 379 ms 80220 KB Output is correct
85 Correct 327 ms 80560 KB Output is correct
86 Correct 595 ms 84628 KB Output is correct
87 Correct 560 ms 84896 KB Output is correct
88 Correct 541 ms 80228 KB Output is correct
89 Correct 507 ms 79552 KB Output is correct
90 Correct 342 ms 80332 KB Output is correct
91 Correct 348 ms 80972 KB Output is correct
92 Correct 3 ms 4948 KB Output is correct
93 Correct 3 ms 4948 KB Output is correct
94 Correct 3 ms 4952 KB Output is correct
95 Correct 3 ms 4948 KB Output is correct
96 Correct 3 ms 4948 KB Output is correct
97 Correct 3 ms 4960 KB Output is correct
98 Correct 619 ms 86836 KB Output is correct
99 Correct 572 ms 82892 KB Output is correct
100 Correct 514 ms 84948 KB Output is correct
101 Correct 467 ms 81444 KB Output is correct
102 Correct 422 ms 81620 KB Output is correct
103 Correct 418 ms 81408 KB Output is correct
104 Correct 383 ms 81952 KB Output is correct
105 Correct 595 ms 88448 KB Output is correct
106 Correct 565 ms 85376 KB Output is correct
107 Correct 538 ms 82872 KB Output is correct
108 Correct 541 ms 79908 KB Output is correct
109 Correct 355 ms 80556 KB Output is correct
110 Correct 364 ms 80912 KB Output is correct
111 Correct 3 ms 4948 KB Output is correct
112 Correct 3 ms 4948 KB Output is correct
113 Correct 3 ms 4948 KB Output is correct
114 Correct 3 ms 4948 KB Output is correct
115 Correct 3 ms 4948 KB Output is correct
116 Correct 527 ms 81100 KB Output is correct
117 Correct 515 ms 79572 KB Output is correct
118 Correct 535 ms 86988 KB Output is correct
119 Correct 496 ms 81428 KB Output is correct
120 Correct 430 ms 81440 KB Output is correct
121 Correct 443 ms 81692 KB Output is correct
122 Correct 379 ms 82108 KB Output is correct
123 Correct 581 ms 87728 KB Output is correct
124 Correct 577 ms 83404 KB Output is correct
125 Correct 531 ms 82580 KB Output is correct
126 Correct 521 ms 79656 KB Output is correct
127 Correct 524 ms 79628 KB Output is correct
128 Correct 409 ms 80624 KB Output is correct
129 Correct 415 ms 80952 KB Output is correct