답안 #892317

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
892317 2023-12-25T07:28:04 Z vjudge1 Sprinkler (JOI22_sprinkler) C++17
3 / 100
200 ms 24148 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()

template<class S, class T>
bool chmin(S &a, const T &b) {
    return a > b && (a = b) == b;
}
template<class S, class T>
bool chmax(S &a, const T &b) {
    return a < b && (a = b) == b;
}
const int inf = 1e9 + 7;
const int INF = 1e18 + 7;
const int mod = 998244353;
const int N = 2e5 + 1;

int n, l;
vector<int> g[N];
vector<int> p(N);
int h[N], cnt[N];

void dfs(int v, int parent, int d, int bound, int w) {
    h[v] *= w;
    h[v] %= l;
    if (d == bound) return;
    for (int to : g[v]) {
        if (to != parent) {
            dfs(to, v, d + 1, bound, w);
        }
    }
}

void walk(int v, int parent) {
    p[v] = parent;
    for (int to : g[v]) {
        if (to != parent) {
            walk(to, v);
        }
    }
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> l;
    for (int i = 1; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    cnt[0] = 1;
    for (int i = 1; i <= n; ++i) {
        cin >> h[i];
        cnt[i] = 1;
    }
    int q;
    cin >> q;
    if (n <= 1000 && q <= 1000) {
        while (q--) {
            int t;
            cin >> t;
            if (t == 1) {
                int v, d, w;
                cin >> v >> d >> w;
                dfs(v, -1, 0, d, w);
            } else {
                int v;
                cin >> v;
                cout << h[v] << '\n';
            }
        }
    } else {
        walk(1, 0);
        while (q--) {
            int t;
            cin >> t;
            if (t == 1) {
                int v, d, w;
                cin >> v >> d >> w;
                if (d == 0) {
                    h[v] *= v;
                    h[v] %= l;
                } else {
                    cnt[p[v]] *= w;
                    cnt[p[v]] %= l;
                }
            } else {
                int v;
                cin >> v;
                int res = h[v];
                if (p[p[v]] != p[v]) {
                    res *= cnt[p[p[v]]];
                    res %= l;
                }
                res *= cnt[p[v]];
                res %= mod;
                res *= cnt[v];
                res %= mod;
                cout << res << '\n';
            }
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9564 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 3 ms 9724 KB Output is correct
5 Correct 4 ms 9564 KB Output is correct
6 Correct 7 ms 9564 KB Output is correct
7 Correct 7 ms 9736 KB Output is correct
8 Correct 9 ms 9564 KB Output is correct
9 Correct 3 ms 9564 KB Output is correct
10 Correct 2 ms 9560 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 2 ms 9564 KB Output is correct
14 Correct 2 ms 9564 KB Output is correct
15 Correct 3 ms 9656 KB Output is correct
16 Correct 3 ms 9564 KB Output is correct
17 Correct 3 ms 9564 KB Output is correct
18 Correct 3 ms 9564 KB Output is correct
19 Correct 3 ms 9560 KB Output is correct
20 Correct 2 ms 9564 KB Output is correct
21 Correct 2 ms 9564 KB Output is correct
22 Correct 3 ms 9564 KB Output is correct
23 Correct 2 ms 9564 KB Output is correct
24 Correct 2 ms 9564 KB Output is correct
25 Correct 2 ms 9564 KB Output is correct
26 Correct 2 ms 9564 KB Output is correct
27 Correct 3 ms 9564 KB Output is correct
28 Correct 3 ms 9564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Incorrect 171 ms 20548 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Incorrect 171 ms 20548 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Incorrect 184 ms 24148 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Incorrect 200 ms 23328 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9564 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 3 ms 9724 KB Output is correct
5 Correct 4 ms 9564 KB Output is correct
6 Correct 7 ms 9564 KB Output is correct
7 Correct 7 ms 9736 KB Output is correct
8 Correct 9 ms 9564 KB Output is correct
9 Correct 3 ms 9564 KB Output is correct
10 Correct 2 ms 9560 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 2 ms 9564 KB Output is correct
14 Correct 2 ms 9564 KB Output is correct
15 Correct 3 ms 9656 KB Output is correct
16 Correct 3 ms 9564 KB Output is correct
17 Correct 3 ms 9564 KB Output is correct
18 Correct 3 ms 9564 KB Output is correct
19 Correct 3 ms 9560 KB Output is correct
20 Correct 2 ms 9564 KB Output is correct
21 Correct 2 ms 9564 KB Output is correct
22 Correct 3 ms 9564 KB Output is correct
23 Correct 2 ms 9564 KB Output is correct
24 Correct 2 ms 9564 KB Output is correct
25 Correct 2 ms 9564 KB Output is correct
26 Correct 2 ms 9564 KB Output is correct
27 Correct 3 ms 9564 KB Output is correct
28 Correct 3 ms 9564 KB Output is correct
29 Correct 2 ms 9564 KB Output is correct
30 Incorrect 171 ms 20548 KB Output isn't correct
31 Halted 0 ms 0 KB -