Submission #957508

# Submission time Handle Problem Language Result Execution time Memory
957508 2024-04-03T23:27:33 Z Pring Sprinkler (JOI22_sprinkler) C++17
100 / 100
746 ms 102152 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif

#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;

const int MXN = 200005, MXC = 45;
int n, q, mod, h[MXN];
vector<int> edge[MXN + MXC];

int p[MXN + MXC];
int drawer[MXN + MXC][MXC];

void ADD_EDGE(int x, int y) {
    edge[x].push_back(y);
    edge[y].push_back(x);
}

void DFS(int id, int par) {
    p[id] = par;
    for (auto &i : edge[id]) {
        if (i == par) continue;
        DFS(i, id);
    }
}

void PRE() {
    ADD_EDGE(1, n + 1);
    FOR(i, n + 1, n + MXC) ADD_EDGE(i, i + 1);
    DFS(n + MXC, 0);
    FOR(i, 1, n + MXC + 1) fill(drawer[i], drawer[i] + MXC, 1);
}

void MODIFY(int id, int d, int v) {
    auto PUT = [&](int id, int slot, int val) -> void {
        if (slot < 0) return;
        drawer[id][slot] = drawer[id][slot] * val % mod;
    };
    int now = id;
    FOR(i, 0, MXC) {
        PUT(now, d - i, v);
        PUT(now, d - i - 1, v);
        now = p[now];
    }
}

int QUERY(int id) {
    int ans = h[id], now = id;
    FOR(i, 0, MXC) {
        ans = ans * drawer[now][i] % mod;
        now = p[now];
    }
    return ans;
}

void miku() {
    int x, y;
    cin >> n >> mod;
    FOR(i, 1, n) {
        cin >> x >> y;
        ADD_EDGE(x, y);
    }
    FOR(i, 1, n + 1) cin >> h[i];
    PRE();
    cin >> q;
    while (q--) {
        int t, x, d, v;
        cin >> t;
        if (t == 1) {
            cin >> x >> d >> v;
            MODIFY(x, d, v);
        } else {
            cin >> x;
            cout << QUERY(x) << '\n';
        }
    }
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    miku();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 3 ms 10844 KB Output is correct
5 Correct 3 ms 10752 KB Output is correct
6 Correct 3 ms 10844 KB Output is correct
7 Correct 3 ms 10844 KB Output is correct
8 Correct 2 ms 10844 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 2 ms 8540 KB Output is correct
15 Correct 2 ms 8536 KB Output is correct
16 Correct 2 ms 8692 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 2 ms 8536 KB Output is correct
19 Correct 2 ms 8540 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 3 ms 8540 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 2 ms 8540 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 2 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 515 ms 93212 KB Output is correct
3 Correct 439 ms 98328 KB Output is correct
4 Correct 505 ms 100436 KB Output is correct
5 Correct 404 ms 98296 KB Output is correct
6 Correct 349 ms 97548 KB Output is correct
7 Correct 277 ms 98388 KB Output is correct
8 Correct 287 ms 98500 KB Output is correct
9 Correct 562 ms 101760 KB Output is correct
10 Correct 470 ms 102104 KB Output is correct
11 Correct 444 ms 98008 KB Output is correct
12 Correct 441 ms 98064 KB Output is correct
13 Correct 207 ms 98220 KB Output is correct
14 Correct 206 ms 98852 KB Output is correct
15 Correct 236 ms 97976 KB Output is correct
16 Correct 218 ms 98536 KB Output is correct
17 Correct 274 ms 99012 KB Output is correct
18 Correct 2 ms 8536 KB Output is correct
19 Correct 2 ms 8672 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 2 ms 8540 KB Output is correct
22 Correct 2 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 515 ms 93212 KB Output is correct
3 Correct 439 ms 98328 KB Output is correct
4 Correct 505 ms 100436 KB Output is correct
5 Correct 404 ms 98296 KB Output is correct
6 Correct 349 ms 97548 KB Output is correct
7 Correct 277 ms 98388 KB Output is correct
8 Correct 287 ms 98500 KB Output is correct
9 Correct 562 ms 101760 KB Output is correct
10 Correct 470 ms 102104 KB Output is correct
11 Correct 444 ms 98008 KB Output is correct
12 Correct 441 ms 98064 KB Output is correct
13 Correct 207 ms 98220 KB Output is correct
14 Correct 206 ms 98852 KB Output is correct
15 Correct 236 ms 97976 KB Output is correct
16 Correct 218 ms 98536 KB Output is correct
17 Correct 274 ms 99012 KB Output is correct
18 Correct 2 ms 8536 KB Output is correct
19 Correct 2 ms 8672 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 2 ms 8540 KB Output is correct
22 Correct 2 ms 8536 KB Output is correct
23 Correct 3 ms 8664 KB Output is correct
24 Correct 562 ms 97808 KB Output is correct
25 Correct 416 ms 98496 KB Output is correct
26 Correct 499 ms 101968 KB Output is correct
27 Correct 471 ms 97876 KB Output is correct
28 Correct 298 ms 98208 KB Output is correct
29 Correct 292 ms 97744 KB Output is correct
30 Correct 293 ms 99200 KB Output is correct
31 Correct 551 ms 100536 KB Output is correct
32 Correct 454 ms 102048 KB Output is correct
33 Correct 476 ms 97896 KB Output is correct
34 Correct 423 ms 98104 KB Output is correct
35 Correct 2 ms 8540 KB Output is correct
36 Correct 3 ms 8796 KB Output is correct
37 Correct 2 ms 8540 KB Output is correct
38 Correct 2 ms 8676 KB Output is correct
39 Correct 2 ms 8536 KB Output is correct
40 Correct 2 ms 8540 KB Output is correct
41 Correct 2 ms 8540 KB Output is correct
42 Correct 2 ms 8680 KB Output is correct
43 Correct 2 ms 8540 KB Output is correct
44 Correct 2 ms 8632 KB Output is correct
45 Correct 2 ms 8540 KB Output is correct
46 Correct 2 ms 8676 KB Output is correct
47 Correct 2 ms 8536 KB Output is correct
48 Correct 2 ms 8540 KB Output is correct
49 Correct 2 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 555 ms 96920 KB Output is correct
3 Correct 684 ms 98536 KB Output is correct
4 Correct 558 ms 98404 KB Output is correct
5 Correct 482 ms 95032 KB Output is correct
6 Correct 321 ms 95276 KB Output is correct
7 Correct 337 ms 95312 KB Output is correct
8 Correct 272 ms 95656 KB Output is correct
9 Correct 589 ms 97756 KB Output is correct
10 Correct 726 ms 99364 KB Output is correct
11 Correct 432 ms 94628 KB Output is correct
12 Correct 531 ms 95572 KB Output is correct
13 Correct 343 ms 96336 KB Output is correct
14 Correct 354 ms 97232 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 2 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 595 ms 97848 KB Output is correct
3 Correct 733 ms 97500 KB Output is correct
4 Correct 568 ms 98764 KB Output is correct
5 Correct 455 ms 96592 KB Output is correct
6 Correct 343 ms 96716 KB Output is correct
7 Correct 320 ms 96460 KB Output is correct
8 Correct 307 ms 96564 KB Output is correct
9 Correct 601 ms 101580 KB Output is correct
10 Correct 728 ms 99928 KB Output is correct
11 Correct 501 ms 97456 KB Output is correct
12 Correct 497 ms 95676 KB Output is correct
13 Correct 341 ms 96460 KB Output is correct
14 Correct 349 ms 97440 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 2 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 3 ms 10844 KB Output is correct
5 Correct 3 ms 10752 KB Output is correct
6 Correct 3 ms 10844 KB Output is correct
7 Correct 3 ms 10844 KB Output is correct
8 Correct 2 ms 10844 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 2 ms 8540 KB Output is correct
15 Correct 2 ms 8536 KB Output is correct
16 Correct 2 ms 8692 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 2 ms 8536 KB Output is correct
19 Correct 2 ms 8540 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 3 ms 8540 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 2 ms 8540 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 2 ms 8540 KB Output is correct
29 Correct 2 ms 8540 KB Output is correct
30 Correct 515 ms 93212 KB Output is correct
31 Correct 439 ms 98328 KB Output is correct
32 Correct 505 ms 100436 KB Output is correct
33 Correct 404 ms 98296 KB Output is correct
34 Correct 349 ms 97548 KB Output is correct
35 Correct 277 ms 98388 KB Output is correct
36 Correct 287 ms 98500 KB Output is correct
37 Correct 562 ms 101760 KB Output is correct
38 Correct 470 ms 102104 KB Output is correct
39 Correct 444 ms 98008 KB Output is correct
40 Correct 441 ms 98064 KB Output is correct
41 Correct 207 ms 98220 KB Output is correct
42 Correct 206 ms 98852 KB Output is correct
43 Correct 236 ms 97976 KB Output is correct
44 Correct 218 ms 98536 KB Output is correct
45 Correct 274 ms 99012 KB Output is correct
46 Correct 2 ms 8536 KB Output is correct
47 Correct 2 ms 8672 KB Output is correct
48 Correct 2 ms 8540 KB Output is correct
49 Correct 2 ms 8540 KB Output is correct
50 Correct 2 ms 8536 KB Output is correct
51 Correct 3 ms 8664 KB Output is correct
52 Correct 562 ms 97808 KB Output is correct
53 Correct 416 ms 98496 KB Output is correct
54 Correct 499 ms 101968 KB Output is correct
55 Correct 471 ms 97876 KB Output is correct
56 Correct 298 ms 98208 KB Output is correct
57 Correct 292 ms 97744 KB Output is correct
58 Correct 293 ms 99200 KB Output is correct
59 Correct 551 ms 100536 KB Output is correct
60 Correct 454 ms 102048 KB Output is correct
61 Correct 476 ms 97896 KB Output is correct
62 Correct 423 ms 98104 KB Output is correct
63 Correct 2 ms 8540 KB Output is correct
64 Correct 3 ms 8796 KB Output is correct
65 Correct 2 ms 8540 KB Output is correct
66 Correct 2 ms 8676 KB Output is correct
67 Correct 2 ms 8536 KB Output is correct
68 Correct 2 ms 8540 KB Output is correct
69 Correct 2 ms 8540 KB Output is correct
70 Correct 2 ms 8680 KB Output is correct
71 Correct 2 ms 8540 KB Output is correct
72 Correct 2 ms 8632 KB Output is correct
73 Correct 2 ms 8540 KB Output is correct
74 Correct 2 ms 8676 KB Output is correct
75 Correct 2 ms 8536 KB Output is correct
76 Correct 2 ms 8540 KB Output is correct
77 Correct 2 ms 8540 KB Output is correct
78 Correct 2 ms 8540 KB Output is correct
79 Correct 555 ms 96920 KB Output is correct
80 Correct 684 ms 98536 KB Output is correct
81 Correct 558 ms 98404 KB Output is correct
82 Correct 482 ms 95032 KB Output is correct
83 Correct 321 ms 95276 KB Output is correct
84 Correct 337 ms 95312 KB Output is correct
85 Correct 272 ms 95656 KB Output is correct
86 Correct 589 ms 97756 KB Output is correct
87 Correct 726 ms 99364 KB Output is correct
88 Correct 432 ms 94628 KB Output is correct
89 Correct 531 ms 95572 KB Output is correct
90 Correct 343 ms 96336 KB Output is correct
91 Correct 354 ms 97232 KB Output is correct
92 Correct 2 ms 8540 KB Output is correct
93 Correct 2 ms 8540 KB Output is correct
94 Correct 2 ms 8540 KB Output is correct
95 Correct 2 ms 8540 KB Output is correct
96 Correct 2 ms 8540 KB Output is correct
97 Correct 2 ms 8540 KB Output is correct
98 Correct 595 ms 97848 KB Output is correct
99 Correct 733 ms 97500 KB Output is correct
100 Correct 568 ms 98764 KB Output is correct
101 Correct 455 ms 96592 KB Output is correct
102 Correct 343 ms 96716 KB Output is correct
103 Correct 320 ms 96460 KB Output is correct
104 Correct 307 ms 96564 KB Output is correct
105 Correct 601 ms 101580 KB Output is correct
106 Correct 728 ms 99928 KB Output is correct
107 Correct 501 ms 97456 KB Output is correct
108 Correct 497 ms 95676 KB Output is correct
109 Correct 341 ms 96460 KB Output is correct
110 Correct 349 ms 97440 KB Output is correct
111 Correct 2 ms 8540 KB Output is correct
112 Correct 2 ms 8540 KB Output is correct
113 Correct 2 ms 8540 KB Output is correct
114 Correct 2 ms 8540 KB Output is correct
115 Correct 2 ms 8540 KB Output is correct
116 Correct 515 ms 95812 KB Output is correct
117 Correct 581 ms 98180 KB Output is correct
118 Correct 596 ms 102152 KB Output is correct
119 Correct 481 ms 98272 KB Output is correct
120 Correct 363 ms 97680 KB Output is correct
121 Correct 388 ms 98404 KB Output is correct
122 Correct 324 ms 98576 KB Output is correct
123 Correct 596 ms 101024 KB Output is correct
124 Correct 746 ms 100336 KB Output is correct
125 Correct 504 ms 97148 KB Output is correct
126 Correct 561 ms 98132 KB Output is correct
127 Correct 574 ms 98900 KB Output is correct
128 Correct 465 ms 99432 KB Output is correct
129 Correct 475 ms 100196 KB Output is correct