Submission #892353

# Submission time Handle Problem Language Result Execution time Memory
892353 2023-12-25T08:42:19 Z vjudge1 Sprinkler (JOI22_sprinkler) C++17
12 / 100
210 ms 25008 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], p(N), h(N), cf(N, 1);

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);
    }
    for (int i = 1; i <= n; ++i) {
        cin >> h[i];
    }
    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] *= w;
                    h[v] %= l;
                } else {
                    h[p[v]] *= w;
                    h[p[v]] %= l;
                    h[v] *= w;
                    h[v] %= l;
                    cf[v] *= w;
                    cf[v] %= l;
                }
            } else {
                int v;
                cin >> v;
                cout << h[v] * cf[p[v]] % l << '\n';
            }
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9816 KB Output is correct
2 Correct 3 ms 9820 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 6 ms 10068 KB Output is correct
6 Correct 7 ms 9908 KB Output is correct
7 Correct 7 ms 9888 KB Output is correct
8 Correct 7 ms 9820 KB Output is correct
9 Correct 3 ms 9820 KB Output is correct
10 Correct 3 ms 9820 KB Output is correct
11 Correct 3 ms 9820 KB Output is correct
12 Correct 3 ms 9820 KB Output is correct
13 Correct 3 ms 9820 KB Output is correct
14 Correct 3 ms 9820 KB Output is correct
15 Correct 3 ms 10072 KB Output is correct
16 Correct 3 ms 9820 KB Output is correct
17 Correct 3 ms 9820 KB Output is correct
18 Correct 3 ms 9820 KB Output is correct
19 Correct 3 ms 9820 KB Output is correct
20 Correct 3 ms 9820 KB Output is correct
21 Correct 3 ms 9820 KB Output is correct
22 Correct 3 ms 9820 KB Output is correct
23 Correct 3 ms 9820 KB Output is correct
24 Correct 3 ms 9820 KB Output is correct
25 Correct 3 ms 9820 KB Output is correct
26 Correct 3 ms 9820 KB Output is correct
27 Correct 3 ms 9820 KB Output is correct
28 Correct 3 ms 9820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9816 KB Output is correct
2 Correct 165 ms 20564 KB Output is correct
3 Correct 192 ms 17536 KB Output is correct
4 Correct 201 ms 21584 KB Output is correct
5 Correct 169 ms 19096 KB Output is correct
6 Correct 181 ms 19340 KB Output is correct
7 Correct 165 ms 19280 KB Output is correct
8 Correct 147 ms 19472 KB Output is correct
9 Correct 209 ms 25008 KB Output is correct
10 Correct 210 ms 21332 KB Output is correct
11 Correct 161 ms 20564 KB Output is correct
12 Correct 190 ms 17492 KB Output is correct
13 Correct 151 ms 17800 KB Output is correct
14 Correct 156 ms 17856 KB Output is correct
15 Correct 163 ms 17848 KB Output is correct
16 Correct 156 ms 17824 KB Output is correct
17 Correct 162 ms 18364 KB Output is correct
18 Correct 3 ms 9820 KB Output is correct
19 Correct 3 ms 9820 KB Output is correct
20 Correct 3 ms 9820 KB Output is correct
21 Correct 3 ms 9820 KB Output is correct
22 Correct 4 ms 9816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9816 KB Output is correct
2 Correct 165 ms 20564 KB Output is correct
3 Correct 192 ms 17536 KB Output is correct
4 Correct 201 ms 21584 KB Output is correct
5 Correct 169 ms 19096 KB Output is correct
6 Correct 181 ms 19340 KB Output is correct
7 Correct 165 ms 19280 KB Output is correct
8 Correct 147 ms 19472 KB Output is correct
9 Correct 209 ms 25008 KB Output is correct
10 Correct 210 ms 21332 KB Output is correct
11 Correct 161 ms 20564 KB Output is correct
12 Correct 190 ms 17492 KB Output is correct
13 Correct 151 ms 17800 KB Output is correct
14 Correct 156 ms 17856 KB Output is correct
15 Correct 163 ms 17848 KB Output is correct
16 Correct 156 ms 17824 KB Output is correct
17 Correct 162 ms 18364 KB Output is correct
18 Correct 3 ms 9820 KB Output is correct
19 Correct 3 ms 9820 KB Output is correct
20 Correct 3 ms 9820 KB Output is correct
21 Correct 3 ms 9820 KB Output is correct
22 Correct 4 ms 9816 KB Output is correct
23 Correct 3 ms 9820 KB Output is correct
24 Incorrect 176 ms 20668 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9816 KB Output is correct
2 Incorrect 202 ms 24108 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10072 KB Output is correct
2 Incorrect 176 ms 23124 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9816 KB Output is correct
2 Correct 3 ms 9820 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 6 ms 10068 KB Output is correct
6 Correct 7 ms 9908 KB Output is correct
7 Correct 7 ms 9888 KB Output is correct
8 Correct 7 ms 9820 KB Output is correct
9 Correct 3 ms 9820 KB Output is correct
10 Correct 3 ms 9820 KB Output is correct
11 Correct 3 ms 9820 KB Output is correct
12 Correct 3 ms 9820 KB Output is correct
13 Correct 3 ms 9820 KB Output is correct
14 Correct 3 ms 9820 KB Output is correct
15 Correct 3 ms 10072 KB Output is correct
16 Correct 3 ms 9820 KB Output is correct
17 Correct 3 ms 9820 KB Output is correct
18 Correct 3 ms 9820 KB Output is correct
19 Correct 3 ms 9820 KB Output is correct
20 Correct 3 ms 9820 KB Output is correct
21 Correct 3 ms 9820 KB Output is correct
22 Correct 3 ms 9820 KB Output is correct
23 Correct 3 ms 9820 KB Output is correct
24 Correct 3 ms 9820 KB Output is correct
25 Correct 3 ms 9820 KB Output is correct
26 Correct 3 ms 9820 KB Output is correct
27 Correct 3 ms 9820 KB Output is correct
28 Correct 3 ms 9820 KB Output is correct
29 Correct 3 ms 9816 KB Output is correct
30 Correct 165 ms 20564 KB Output is correct
31 Correct 192 ms 17536 KB Output is correct
32 Correct 201 ms 21584 KB Output is correct
33 Correct 169 ms 19096 KB Output is correct
34 Correct 181 ms 19340 KB Output is correct
35 Correct 165 ms 19280 KB Output is correct
36 Correct 147 ms 19472 KB Output is correct
37 Correct 209 ms 25008 KB Output is correct
38 Correct 210 ms 21332 KB Output is correct
39 Correct 161 ms 20564 KB Output is correct
40 Correct 190 ms 17492 KB Output is correct
41 Correct 151 ms 17800 KB Output is correct
42 Correct 156 ms 17856 KB Output is correct
43 Correct 163 ms 17848 KB Output is correct
44 Correct 156 ms 17824 KB Output is correct
45 Correct 162 ms 18364 KB Output is correct
46 Correct 3 ms 9820 KB Output is correct
47 Correct 3 ms 9820 KB Output is correct
48 Correct 3 ms 9820 KB Output is correct
49 Correct 3 ms 9820 KB Output is correct
50 Correct 4 ms 9816 KB Output is correct
51 Correct 3 ms 9820 KB Output is correct
52 Incorrect 176 ms 20668 KB Output isn't correct
53 Halted 0 ms 0 KB -