답안 #721471

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
721471 2023-04-11T02:08:29 Z becaido Sprinkler (JOI22_sprinkler) C++17
100 / 100
892 ms 58024 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout (T t, U...u) {cout << t << (sizeof... (u) ? ", " : ""), dout (u...);}
#else
#define debug(...) 7122
#endif

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

const int SIZE = 2e5 + 5;
const int MAX = 41;

int n, mod, q;
int a[SIZE];
vector<int> adj[SIZE];
int pa[SIZE], val[SIZE][MAX];

void solve() {
    cin >> n >> mod;
    FOR (i, 2, n) {
        int a, b;
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    FOR (i, 1, n) {
        cin >> a[i];
        fill(val[i], val[i] + MAX, 1);
    }
    auto dfs = [&](auto dfs, int pos)->void {
        for (int np : adj[pos]) if (np != pa[pos]) {
            pa[np] = pos;
            dfs(dfs, np);
        }
    };
    dfs(dfs, 1);
    cin >> q;
    while (q--) {
        int ty, x, d, w;
        cin >> ty;
        if (ty == 1) {
            cin >> x >> d >> w;
            for (int pos = x, i = d; i >= 0; i--) {
                val[pos][i] = 1ll * val[pos][i] * w % mod;
                if (i >= 1) val[pos][i - 1] = 1ll * val[pos][i - 1] * w % mod;
                if (pos == 1) i--;
                else pos = pa[pos];
            }
        }
        if (ty == 2) {
            cin >> x;
            int ans = a[x];
            for (int pos = x, i = 0; pos && i < MAX; pos = pa[pos], i++) ans = 1ll * ans * val[pos][i] % mod;
            cout << ans << '\n';
        }
    }
}

int main() {
    Waimai;
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 4 ms 5204 KB Output is correct
6 Correct 4 ms 5204 KB Output is correct
7 Correct 4 ms 5204 KB Output is correct
8 Correct 4 ms 5204 KB Output is correct
9 Correct 4 ms 4948 KB Output is correct
10 Correct 4 ms 4948 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 3 ms 5052 KB Output is correct
13 Correct 4 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 4 ms 5044 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 4 ms 4948 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 4 ms 4948 KB Output is correct
23 Correct 4 ms 5044 KB Output is correct
24 Correct 4 ms 4948 KB Output is correct
25 Correct 3 ms 5036 KB Output is correct
26 Correct 4 ms 4948 KB Output is correct
27 Correct 4 ms 5040 KB Output is correct
28 Correct 4 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5032 KB Output is correct
2 Correct 496 ms 51896 KB Output is correct
3 Correct 368 ms 48632 KB Output is correct
4 Correct 451 ms 54444 KB Output is correct
5 Correct 440 ms 50108 KB Output is correct
6 Correct 352 ms 50124 KB Output is correct
7 Correct 334 ms 50460 KB Output is correct
8 Correct 275 ms 50972 KB Output is correct
9 Correct 651 ms 58024 KB Output is correct
10 Correct 410 ms 54468 KB Output is correct
11 Correct 519 ms 51768 KB Output is correct
12 Correct 336 ms 48580 KB Output is correct
13 Correct 274 ms 49132 KB Output is correct
14 Correct 232 ms 49328 KB Output is correct
15 Correct 258 ms 49216 KB Output is correct
16 Correct 243 ms 49180 KB Output is correct
17 Correct 259 ms 49732 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 4 ms 5040 KB Output is correct
20 Correct 6 ms 4948 KB Output is correct
21 Correct 6 ms 4984 KB Output is correct
22 Correct 4 ms 5044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5032 KB Output is correct
2 Correct 496 ms 51896 KB Output is correct
3 Correct 368 ms 48632 KB Output is correct
4 Correct 451 ms 54444 KB Output is correct
5 Correct 440 ms 50108 KB Output is correct
6 Correct 352 ms 50124 KB Output is correct
7 Correct 334 ms 50460 KB Output is correct
8 Correct 275 ms 50972 KB Output is correct
9 Correct 651 ms 58024 KB Output is correct
10 Correct 410 ms 54468 KB Output is correct
11 Correct 519 ms 51768 KB Output is correct
12 Correct 336 ms 48580 KB Output is correct
13 Correct 274 ms 49132 KB Output is correct
14 Correct 232 ms 49328 KB Output is correct
15 Correct 258 ms 49216 KB Output is correct
16 Correct 243 ms 49180 KB Output is correct
17 Correct 259 ms 49732 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 4 ms 5040 KB Output is correct
20 Correct 6 ms 4948 KB Output is correct
21 Correct 6 ms 4984 KB Output is correct
22 Correct 4 ms 5044 KB Output is correct
23 Correct 6 ms 4956 KB Output is correct
24 Correct 751 ms 51720 KB Output is correct
25 Correct 472 ms 48760 KB Output is correct
26 Correct 529 ms 56392 KB Output is correct
27 Correct 437 ms 50380 KB Output is correct
28 Correct 347 ms 50396 KB Output is correct
29 Correct 422 ms 50424 KB Output is correct
30 Correct 279 ms 50956 KB Output is correct
31 Correct 613 ms 56328 KB Output is correct
32 Correct 427 ms 54520 KB Output is correct
33 Correct 681 ms 51872 KB Output is correct
34 Correct 482 ms 48676 KB Output is correct
35 Correct 4 ms 5040 KB Output is correct
36 Correct 4 ms 5044 KB Output is correct
37 Correct 4 ms 5040 KB Output is correct
38 Correct 4 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 4 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 4 ms 4948 KB Output is correct
44 Correct 4 ms 4948 KB Output is correct
45 Correct 4 ms 4948 KB Output is correct
46 Correct 4 ms 4948 KB Output is correct
47 Correct 5 ms 5040 KB Output is correct
48 Correct 4 ms 5052 KB Output is correct
49 Correct 4 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 666 ms 55676 KB Output is correct
3 Correct 776 ms 53252 KB Output is correct
4 Correct 651 ms 53940 KB Output is correct
5 Correct 617 ms 48860 KB Output is correct
6 Correct 439 ms 48920 KB Output is correct
7 Correct 325 ms 49076 KB Output is correct
8 Correct 293 ms 49572 KB Output is correct
9 Correct 699 ms 53876 KB Output is correct
10 Correct 874 ms 54264 KB Output is correct
11 Correct 620 ms 49264 KB Output is correct
12 Correct 663 ms 48580 KB Output is correct
13 Correct 455 ms 49464 KB Output is correct
14 Correct 431 ms 49876 KB Output is correct
15 Correct 4 ms 5036 KB Output is correct
16 Correct 6 ms 5040 KB Output is correct
17 Correct 4 ms 4948 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5032 KB Output is correct
2 Correct 735 ms 56228 KB Output is correct
3 Correct 892 ms 52020 KB Output is correct
4 Correct 647 ms 54204 KB Output is correct
5 Correct 524 ms 50420 KB Output is correct
6 Correct 441 ms 50552 KB Output is correct
7 Correct 404 ms 50448 KB Output is correct
8 Correct 302 ms 50952 KB Output is correct
9 Correct 735 ms 57968 KB Output is correct
10 Correct 839 ms 54868 KB Output is correct
11 Correct 576 ms 52096 KB Output is correct
12 Correct 653 ms 48780 KB Output is correct
13 Correct 519 ms 49580 KB Output is correct
14 Correct 447 ms 49976 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 4 ms 5076 KB Output is correct
17 Correct 3 ms 4964 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 4 ms 5204 KB Output is correct
6 Correct 4 ms 5204 KB Output is correct
7 Correct 4 ms 5204 KB Output is correct
8 Correct 4 ms 5204 KB Output is correct
9 Correct 4 ms 4948 KB Output is correct
10 Correct 4 ms 4948 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 3 ms 5052 KB Output is correct
13 Correct 4 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 4 ms 5044 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 4 ms 4948 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 4 ms 4948 KB Output is correct
23 Correct 4 ms 5044 KB Output is correct
24 Correct 4 ms 4948 KB Output is correct
25 Correct 3 ms 5036 KB Output is correct
26 Correct 4 ms 4948 KB Output is correct
27 Correct 4 ms 5040 KB Output is correct
28 Correct 4 ms 4948 KB Output is correct
29 Correct 5 ms 5032 KB Output is correct
30 Correct 496 ms 51896 KB Output is correct
31 Correct 368 ms 48632 KB Output is correct
32 Correct 451 ms 54444 KB Output is correct
33 Correct 440 ms 50108 KB Output is correct
34 Correct 352 ms 50124 KB Output is correct
35 Correct 334 ms 50460 KB Output is correct
36 Correct 275 ms 50972 KB Output is correct
37 Correct 651 ms 58024 KB Output is correct
38 Correct 410 ms 54468 KB Output is correct
39 Correct 519 ms 51768 KB Output is correct
40 Correct 336 ms 48580 KB Output is correct
41 Correct 274 ms 49132 KB Output is correct
42 Correct 232 ms 49328 KB Output is correct
43 Correct 258 ms 49216 KB Output is correct
44 Correct 243 ms 49180 KB Output is correct
45 Correct 259 ms 49732 KB Output is correct
46 Correct 4 ms 4948 KB Output is correct
47 Correct 4 ms 5040 KB Output is correct
48 Correct 6 ms 4948 KB Output is correct
49 Correct 6 ms 4984 KB Output is correct
50 Correct 4 ms 5044 KB Output is correct
51 Correct 6 ms 4956 KB Output is correct
52 Correct 751 ms 51720 KB Output is correct
53 Correct 472 ms 48760 KB Output is correct
54 Correct 529 ms 56392 KB Output is correct
55 Correct 437 ms 50380 KB Output is correct
56 Correct 347 ms 50396 KB Output is correct
57 Correct 422 ms 50424 KB Output is correct
58 Correct 279 ms 50956 KB Output is correct
59 Correct 613 ms 56328 KB Output is correct
60 Correct 427 ms 54520 KB Output is correct
61 Correct 681 ms 51872 KB Output is correct
62 Correct 482 ms 48676 KB Output is correct
63 Correct 4 ms 5040 KB Output is correct
64 Correct 4 ms 5044 KB Output is correct
65 Correct 4 ms 5040 KB Output is correct
66 Correct 4 ms 4948 KB Output is correct
67 Correct 3 ms 4948 KB Output is correct
68 Correct 4 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 4 ms 4948 KB Output is correct
72 Correct 4 ms 4948 KB Output is correct
73 Correct 4 ms 4948 KB Output is correct
74 Correct 4 ms 4948 KB Output is correct
75 Correct 5 ms 5040 KB Output is correct
76 Correct 4 ms 5052 KB Output is correct
77 Correct 4 ms 4948 KB Output is correct
78 Correct 4 ms 4948 KB Output is correct
79 Correct 666 ms 55676 KB Output is correct
80 Correct 776 ms 53252 KB Output is correct
81 Correct 651 ms 53940 KB Output is correct
82 Correct 617 ms 48860 KB Output is correct
83 Correct 439 ms 48920 KB Output is correct
84 Correct 325 ms 49076 KB Output is correct
85 Correct 293 ms 49572 KB Output is correct
86 Correct 699 ms 53876 KB Output is correct
87 Correct 874 ms 54264 KB Output is correct
88 Correct 620 ms 49264 KB Output is correct
89 Correct 663 ms 48580 KB Output is correct
90 Correct 455 ms 49464 KB Output is correct
91 Correct 431 ms 49876 KB Output is correct
92 Correct 4 ms 5036 KB Output is correct
93 Correct 6 ms 5040 KB Output is correct
94 Correct 4 ms 4948 KB Output is correct
95 Correct 4 ms 4948 KB Output is correct
96 Correct 3 ms 4948 KB Output is correct
97 Correct 4 ms 5032 KB Output is correct
98 Correct 735 ms 56228 KB Output is correct
99 Correct 892 ms 52020 KB Output is correct
100 Correct 647 ms 54204 KB Output is correct
101 Correct 524 ms 50420 KB Output is correct
102 Correct 441 ms 50552 KB Output is correct
103 Correct 404 ms 50448 KB Output is correct
104 Correct 302 ms 50952 KB Output is correct
105 Correct 735 ms 57968 KB Output is correct
106 Correct 839 ms 54868 KB Output is correct
107 Correct 576 ms 52096 KB Output is correct
108 Correct 653 ms 48780 KB Output is correct
109 Correct 519 ms 49580 KB Output is correct
110 Correct 447 ms 49976 KB Output is correct
111 Correct 4 ms 4948 KB Output is correct
112 Correct 4 ms 5076 KB Output is correct
113 Correct 3 ms 4964 KB Output is correct
114 Correct 4 ms 4948 KB Output is correct
115 Correct 4 ms 4948 KB Output is correct
116 Correct 628 ms 47316 KB Output is correct
117 Correct 613 ms 45800 KB Output is correct
118 Correct 578 ms 53576 KB Output is correct
119 Correct 545 ms 47780 KB Output is correct
120 Correct 406 ms 47576 KB Output is correct
121 Correct 429 ms 47920 KB Output is correct
122 Correct 299 ms 48508 KB Output is correct
123 Correct 630 ms 54308 KB Output is correct
124 Correct 861 ms 49976 KB Output is correct
125 Correct 532 ms 48628 KB Output is correct
126 Correct 638 ms 45968 KB Output is correct
127 Correct 641 ms 45860 KB Output is correct
128 Correct 517 ms 46776 KB Output is correct
129 Correct 538 ms 47268 KB Output is correct