답안 #905776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
905776 2024-01-13T04:45:01 Z Tuanlinh123 Sprinkler (JOI22_sprinkler) C++17
100 / 100
1086 ms 101776 KB
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;

const ll maxn=200005;
ll h[maxn], pa[maxn], m[maxn][45];
vector <ll> A[maxn];

void dfs(ll u)
{
    for (ll v:A[u])
        if (v!=pa[u])
            pa[v]=u, dfs(v);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, Mod; cin >> n >> Mod;
    for (ll i=1; i<=n; i++)
        for (ll j=0; j<=40; j++)
            m[i][j]=1;
    for (ll i=1; i<n; i++)
    {
        ll u, v; cin >> u >> v;
        A[u].pb(v); A[v].pb(u);
    }
    dfs(1);
    for (ll i=1; i<=n; i++)
        cin >> h[i];
    ll q; cin >> q;
    for (ll i=1; i<=q; i++)
    {
        ll t, x; cin >> t >> x;
        if (t==1)
        {
            ll d, w; cin >> d >> w;
            while (d>=0 && x)
            {
                if (x==1)
                {
                    for (ll i=d; i>=0; i--)
                        m[x][i]=m[x][i]*w%Mod;
                    break;
                }
                m[x][d]=m[x][d]*w%Mod;
                if (d) m[x][d-1]=m[x][d-1]*w%Mod;
                d--, x=pa[x];
            }
        }
        else
        {
            ll dis=0, ans=h[x];
            while (dis<=40 && x)
            {
                ans=ans*m[x][dis]%Mod;
                dis++, x=pa[x];
            }
            cout << ans << "\n";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 4 ms 9052 KB Output is correct
4 Correct 4 ms 9108 KB Output is correct
5 Correct 4 ms 8796 KB Output is correct
6 Correct 4 ms 8796 KB Output is correct
7 Correct 4 ms 9096 KB Output is correct
8 Correct 4 ms 9052 KB Output is correct
9 Correct 3 ms 8952 KB Output is correct
10 Correct 3 ms 8796 KB Output is correct
11 Correct 4 ms 8796 KB Output is correct
12 Correct 4 ms 8796 KB Output is correct
13 Correct 3 ms 8856 KB Output is correct
14 Correct 3 ms 8796 KB Output is correct
15 Correct 3 ms 8948 KB Output is correct
16 Correct 3 ms 8796 KB Output is correct
17 Correct 3 ms 8796 KB Output is correct
18 Correct 4 ms 8804 KB Output is correct
19 Correct 3 ms 8796 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
21 Correct 2 ms 8952 KB Output is correct
22 Correct 3 ms 8796 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 3 ms 8848 KB Output is correct
25 Correct 3 ms 8796 KB Output is correct
26 Correct 3 ms 8952 KB Output is correct
27 Correct 3 ms 8796 KB Output is correct
28 Correct 3 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8796 KB Output is correct
2 Correct 517 ms 97692 KB Output is correct
3 Correct 452 ms 98324 KB Output is correct
4 Correct 648 ms 100380 KB Output is correct
5 Correct 464 ms 97996 KB Output is correct
6 Correct 374 ms 97472 KB Output is correct
7 Correct 355 ms 98524 KB Output is correct
8 Correct 281 ms 98712 KB Output is correct
9 Correct 753 ms 101556 KB Output is correct
10 Correct 465 ms 101628 KB Output is correct
11 Correct 544 ms 97684 KB Output is correct
12 Correct 376 ms 98268 KB Output is correct
13 Correct 260 ms 98384 KB Output is correct
14 Correct 244 ms 98808 KB Output is correct
15 Correct 272 ms 97916 KB Output is correct
16 Correct 215 ms 98564 KB Output is correct
17 Correct 290 ms 99004 KB Output is correct
18 Correct 4 ms 8796 KB Output is correct
19 Correct 3 ms 9048 KB Output is correct
20 Correct 3 ms 8856 KB Output is correct
21 Correct 3 ms 9048 KB Output is correct
22 Correct 3 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8796 KB Output is correct
2 Correct 517 ms 97692 KB Output is correct
3 Correct 452 ms 98324 KB Output is correct
4 Correct 648 ms 100380 KB Output is correct
5 Correct 464 ms 97996 KB Output is correct
6 Correct 374 ms 97472 KB Output is correct
7 Correct 355 ms 98524 KB Output is correct
8 Correct 281 ms 98712 KB Output is correct
9 Correct 753 ms 101556 KB Output is correct
10 Correct 465 ms 101628 KB Output is correct
11 Correct 544 ms 97684 KB Output is correct
12 Correct 376 ms 98268 KB Output is correct
13 Correct 260 ms 98384 KB Output is correct
14 Correct 244 ms 98808 KB Output is correct
15 Correct 272 ms 97916 KB Output is correct
16 Correct 215 ms 98564 KB Output is correct
17 Correct 290 ms 99004 KB Output is correct
18 Correct 4 ms 8796 KB Output is correct
19 Correct 3 ms 9048 KB Output is correct
20 Correct 3 ms 8856 KB Output is correct
21 Correct 3 ms 9048 KB Output is correct
22 Correct 3 ms 8796 KB Output is correct
23 Correct 2 ms 8844 KB Output is correct
24 Correct 572 ms 97616 KB Output is correct
25 Correct 426 ms 98188 KB Output is correct
26 Correct 626 ms 101776 KB Output is correct
27 Correct 496 ms 98000 KB Output is correct
28 Correct 395 ms 98072 KB Output is correct
29 Correct 399 ms 97860 KB Output is correct
30 Correct 253 ms 98712 KB Output is correct
31 Correct 782 ms 100312 KB Output is correct
32 Correct 461 ms 101688 KB Output is correct
33 Correct 595 ms 97784 KB Output is correct
34 Correct 349 ms 98396 KB Output is correct
35 Correct 3 ms 8796 KB Output is correct
36 Correct 2 ms 8796 KB Output is correct
37 Correct 3 ms 8796 KB Output is correct
38 Correct 3 ms 8796 KB Output is correct
39 Correct 3 ms 8796 KB Output is correct
40 Correct 3 ms 8848 KB Output is correct
41 Correct 3 ms 8796 KB Output is correct
42 Correct 3 ms 8856 KB Output is correct
43 Correct 2 ms 8796 KB Output is correct
44 Correct 3 ms 8796 KB Output is correct
45 Correct 3 ms 8796 KB Output is correct
46 Correct 3 ms 8948 KB Output is correct
47 Correct 3 ms 8796 KB Output is correct
48 Correct 3 ms 8796 KB Output is correct
49 Correct 4 ms 8808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8952 KB Output is correct
2 Correct 934 ms 98816 KB Output is correct
3 Correct 1080 ms 98292 KB Output is correct
4 Correct 812 ms 97980 KB Output is correct
5 Correct 592 ms 94992 KB Output is correct
6 Correct 438 ms 95144 KB Output is correct
7 Correct 389 ms 95364 KB Output is correct
8 Correct 295 ms 95656 KB Output is correct
9 Correct 816 ms 97356 KB Output is correct
10 Correct 935 ms 98692 KB Output is correct
11 Correct 510 ms 94524 KB Output is correct
12 Correct 490 ms 95412 KB Output is correct
13 Correct 477 ms 96444 KB Output is correct
14 Correct 447 ms 97152 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 3 ms 8852 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 3 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 809 ms 99848 KB Output is correct
3 Correct 1086 ms 97336 KB Output is correct
4 Correct 756 ms 98728 KB Output is correct
5 Correct 600 ms 96536 KB Output is correct
6 Correct 415 ms 96692 KB Output is correct
7 Correct 354 ms 96544 KB Output is correct
8 Correct 258 ms 96512 KB Output is correct
9 Correct 814 ms 101000 KB Output is correct
10 Correct 1041 ms 99452 KB Output is correct
11 Correct 573 ms 97260 KB Output is correct
12 Correct 592 ms 96340 KB Output is correct
13 Correct 423 ms 96588 KB Output is correct
14 Correct 418 ms 97376 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 3 ms 8796 KB Output is correct
18 Correct 3 ms 8796 KB Output is correct
19 Correct 3 ms 9052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 4 ms 9052 KB Output is correct
4 Correct 4 ms 9108 KB Output is correct
5 Correct 4 ms 8796 KB Output is correct
6 Correct 4 ms 8796 KB Output is correct
7 Correct 4 ms 9096 KB Output is correct
8 Correct 4 ms 9052 KB Output is correct
9 Correct 3 ms 8952 KB Output is correct
10 Correct 3 ms 8796 KB Output is correct
11 Correct 4 ms 8796 KB Output is correct
12 Correct 4 ms 8796 KB Output is correct
13 Correct 3 ms 8856 KB Output is correct
14 Correct 3 ms 8796 KB Output is correct
15 Correct 3 ms 8948 KB Output is correct
16 Correct 3 ms 8796 KB Output is correct
17 Correct 3 ms 8796 KB Output is correct
18 Correct 4 ms 8804 KB Output is correct
19 Correct 3 ms 8796 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
21 Correct 2 ms 8952 KB Output is correct
22 Correct 3 ms 8796 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 3 ms 8848 KB Output is correct
25 Correct 3 ms 8796 KB Output is correct
26 Correct 3 ms 8952 KB Output is correct
27 Correct 3 ms 8796 KB Output is correct
28 Correct 3 ms 8796 KB Output is correct
29 Correct 3 ms 8796 KB Output is correct
30 Correct 517 ms 97692 KB Output is correct
31 Correct 452 ms 98324 KB Output is correct
32 Correct 648 ms 100380 KB Output is correct
33 Correct 464 ms 97996 KB Output is correct
34 Correct 374 ms 97472 KB Output is correct
35 Correct 355 ms 98524 KB Output is correct
36 Correct 281 ms 98712 KB Output is correct
37 Correct 753 ms 101556 KB Output is correct
38 Correct 465 ms 101628 KB Output is correct
39 Correct 544 ms 97684 KB Output is correct
40 Correct 376 ms 98268 KB Output is correct
41 Correct 260 ms 98384 KB Output is correct
42 Correct 244 ms 98808 KB Output is correct
43 Correct 272 ms 97916 KB Output is correct
44 Correct 215 ms 98564 KB Output is correct
45 Correct 290 ms 99004 KB Output is correct
46 Correct 4 ms 8796 KB Output is correct
47 Correct 3 ms 9048 KB Output is correct
48 Correct 3 ms 8856 KB Output is correct
49 Correct 3 ms 9048 KB Output is correct
50 Correct 3 ms 8796 KB Output is correct
51 Correct 2 ms 8844 KB Output is correct
52 Correct 572 ms 97616 KB Output is correct
53 Correct 426 ms 98188 KB Output is correct
54 Correct 626 ms 101776 KB Output is correct
55 Correct 496 ms 98000 KB Output is correct
56 Correct 395 ms 98072 KB Output is correct
57 Correct 399 ms 97860 KB Output is correct
58 Correct 253 ms 98712 KB Output is correct
59 Correct 782 ms 100312 KB Output is correct
60 Correct 461 ms 101688 KB Output is correct
61 Correct 595 ms 97784 KB Output is correct
62 Correct 349 ms 98396 KB Output is correct
63 Correct 3 ms 8796 KB Output is correct
64 Correct 2 ms 8796 KB Output is correct
65 Correct 3 ms 8796 KB Output is correct
66 Correct 3 ms 8796 KB Output is correct
67 Correct 3 ms 8796 KB Output is correct
68 Correct 3 ms 8848 KB Output is correct
69 Correct 3 ms 8796 KB Output is correct
70 Correct 3 ms 8856 KB Output is correct
71 Correct 2 ms 8796 KB Output is correct
72 Correct 3 ms 8796 KB Output is correct
73 Correct 3 ms 8796 KB Output is correct
74 Correct 3 ms 8948 KB Output is correct
75 Correct 3 ms 8796 KB Output is correct
76 Correct 3 ms 8796 KB Output is correct
77 Correct 4 ms 8808 KB Output is correct
78 Correct 3 ms 8952 KB Output is correct
79 Correct 934 ms 98816 KB Output is correct
80 Correct 1080 ms 98292 KB Output is correct
81 Correct 812 ms 97980 KB Output is correct
82 Correct 592 ms 94992 KB Output is correct
83 Correct 438 ms 95144 KB Output is correct
84 Correct 389 ms 95364 KB Output is correct
85 Correct 295 ms 95656 KB Output is correct
86 Correct 816 ms 97356 KB Output is correct
87 Correct 935 ms 98692 KB Output is correct
88 Correct 510 ms 94524 KB Output is correct
89 Correct 490 ms 95412 KB Output is correct
90 Correct 477 ms 96444 KB Output is correct
91 Correct 447 ms 97152 KB Output is correct
92 Correct 2 ms 8796 KB Output is correct
93 Correct 2 ms 8796 KB Output is correct
94 Correct 3 ms 8852 KB Output is correct
95 Correct 2 ms 8796 KB Output is correct
96 Correct 3 ms 8796 KB Output is correct
97 Correct 2 ms 8796 KB Output is correct
98 Correct 809 ms 99848 KB Output is correct
99 Correct 1086 ms 97336 KB Output is correct
100 Correct 756 ms 98728 KB Output is correct
101 Correct 600 ms 96536 KB Output is correct
102 Correct 415 ms 96692 KB Output is correct
103 Correct 354 ms 96544 KB Output is correct
104 Correct 258 ms 96512 KB Output is correct
105 Correct 814 ms 101000 KB Output is correct
106 Correct 1041 ms 99452 KB Output is correct
107 Correct 573 ms 97260 KB Output is correct
108 Correct 592 ms 96340 KB Output is correct
109 Correct 423 ms 96588 KB Output is correct
110 Correct 418 ms 97376 KB Output is correct
111 Correct 2 ms 8796 KB Output is correct
112 Correct 2 ms 8796 KB Output is correct
113 Correct 3 ms 8796 KB Output is correct
114 Correct 3 ms 8796 KB Output is correct
115 Correct 3 ms 9052 KB Output is correct
116 Correct 607 ms 95952 KB Output is correct
117 Correct 657 ms 98412 KB Output is correct
118 Correct 768 ms 101596 KB Output is correct
119 Correct 551 ms 97984 KB Output is correct
120 Correct 439 ms 97552 KB Output is correct
121 Correct 466 ms 98448 KB Output is correct
122 Correct 345 ms 98456 KB Output is correct
123 Correct 728 ms 100560 KB Output is correct
124 Correct 1018 ms 100044 KB Output is correct
125 Correct 605 ms 97036 KB Output is correct
126 Correct 752 ms 98504 KB Output is correct
127 Correct 1061 ms 98796 KB Output is correct
128 Correct 597 ms 99492 KB Output is correct
129 Correct 605 ms 100332 KB Output is correct