Submission #954044

# Submission time Handle Problem Language Result Execution time Memory
954044 2024-03-27T07:00:38 Z Pring Sprinkler (JOI22_sprinkler) C++17
0 / 100
319 ms 27116 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 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, MXD = 40;
int n, q, mod, h[MXN];
vector<int> edge[MXN];


namespace SB1 {

    void DFS(int id, int par, int rst, int w) {
        h[id] = h[id] * w % mod;
        if (rst == 0) return;
        for (auto &i : edge[id]) {
            if (i == par) continue;
            DFS(i, id, rst - 1, w);
        }
    }

    void solve() {
        cin >> q;
        while (q--) {
            int t, x, d, w;
            cin >> t;
            if (t == 1) {
                cin >> x >> d >> w;
                DFS(x, 0, d, w);
            } else {
                cin >> x;
                cout << h[x] << '\n';
            }
        }
    }
}

namespace SB4 {
    int p[MXN];
    int d[MXN];

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

    void modify(int x, int r) {
        int now = x;
        for (int i = r; i >= 0; i--) {
            d[now] = i;
            if (p[now] == 0) return;
            now = p[now];
        }
    }

    bool alive(int x) {
        int now = x;
        FOR(i, 0, 41) {
            if (d[now] > i) return false;
            if (p[now] == 0) return true;
            now = p[now];
        }
        return true;
    }

    void solve() {
        DFS(1, 0);
        fill(d + 1, d + n + 1, -1);
        cin >> q;
        while (q--) {
            int t, x, d, w;
            cin >> t;
            if (t == 1) {
                cin >> x >> d >> w;
                modify(x, d);
            } else {
                cin >> x;
                cout << (alive(x) ? h[x] : 0) << '\n';
            }
        }
    }
}

void miku() {
    int x, y;
    cin >> n >> mod;
    FOR(i, 1, n) {
        cin >> x >> y;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    FOR(i, 1, n + 1) cin >> h[i];
    if (n <= 1000) SB1::solve();
    else SB4::solve();
}

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 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Incorrect 2 ms 6492 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Incorrect 319 ms 25192 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Incorrect 319 ms 25192 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Incorrect 219 ms 27116 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Incorrect 187 ms 25664 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Incorrect 2 ms 6492 KB Output isn't correct
5 Halted 0 ms 0 KB -