Submission #957507

# Submission time Handle Problem Language Result Execution time Memory
957507 2024-04-03T23:25:33 Z Pring Sprinkler (JOI22_sprinkler) C++17
3 / 100
101 ms 36684 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];
int drawer[MXN][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 2 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 11092 KB Output is correct
5 Correct 3 ms 10844 KB Output is correct
6 Correct 3 ms 10840 KB Output is correct
7 Correct 3 ms 10844 KB Output is correct
8 Correct 3 ms 10968 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 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8536 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 2 ms 8540 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 8540 KB Output is correct
23 Correct 2 ms 8540 KB Output is correct
24 Correct 2 ms 8536 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 8672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Runtime error 76 ms 36684 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Runtime error 76 ms 36684 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Runtime error 92 ms 34560 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Runtime error 101 ms 34728 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 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 11092 KB Output is correct
5 Correct 3 ms 10844 KB Output is correct
6 Correct 3 ms 10840 KB Output is correct
7 Correct 3 ms 10844 KB Output is correct
8 Correct 3 ms 10968 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 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8536 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 2 ms 8540 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 8540 KB Output is correct
23 Correct 2 ms 8540 KB Output is correct
24 Correct 2 ms 8536 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 8672 KB Output is correct
29 Correct 2 ms 8536 KB Output is correct
30 Runtime error 76 ms 36684 KB Execution killed with signal 11
31 Halted 0 ms 0 KB -