Submission #1097023

# Submission time Handle Problem Language Result Execution time Memory
1097023 2024-10-05T19:16:34 Z efishel Sprinkler (JOI22_sprinkler) C++17
3 / 100
4000 ms 595028 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using ii = pair <ll, ll>;
using vii = vector <ii>;

const ll MAXN = 2.1E5, MAXD = 42;
vll adj[MAXN];
ll L;
ll ve[MAXN];
map <ll, ll> dp[MAXN]; // children of u at depth j should be multed by dp[u][j]
ll par[MAXN], dep[MAXN];

void dfs (ll u, ll par) {
    ::par[u] = par;
    for (ll d = dep[u]; d <= dep[u]+MAXD; d++) dp[u][d] = 1;
    for (ll v : adj[u]) {
        if (v == par) continue;
        dep[v] = dep[u]+1;
        dfs(v, u);
    }
}

int main () {
    cin.tie(nullptr) -> sync_with_stdio(false);
    ll n;
    cin >> n >> L;
    for (ll i = 1; i < n; i++) {
        ll u, v;
        cin >> u >> v;
        u += 50; v += 50;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (ll i = 1+50; i <= n+50; i++) cin >> ve[i];
    for (ll i = 0; i <= 50; i++) adj[i].push_back(i+1);
    dep[0] = 0;
    dfs(0, 0);
    ll Q;
    cin >> Q;
    for (ll q = 0; q < Q; q++) {
        char type;
        cin >> type;
        switch (type) {
            case '1':
            {ll u, maxD, w;
            cin >> u >> maxD >> w;
            u += 50;
            ll uo = u;
            for (ll d = 0; d < maxD; d++) {
                (dp[u][dep[uo]+maxD-2*d] *= w) %= L;
                (dp[u][dep[uo]+maxD-2*d-1] *= w) %= L;
                u = par[u];
            }
            (dp[u][dep[u]] *= w) %= L;
            break;}
            case '2':
            {ll u;
            cin >> u;
            u += 50;
            ll uo = u;
            ll ans = ve[u];
            for (ll i = 0; i < MAXD; i++, u = par[u]) {
                (ans *= dp[u][dep[uo]]) %= L;
            }
            cout << ans << '\n';
            break;}
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15192 KB Output is correct
2 Correct 6 ms 15196 KB Output is correct
3 Correct 10 ms 15272 KB Output is correct
4 Correct 10 ms 18008 KB Output is correct
5 Correct 10 ms 18012 KB Output is correct
6 Correct 10 ms 18012 KB Output is correct
7 Correct 11 ms 18012 KB Output is correct
8 Correct 11 ms 18008 KB Output is correct
9 Correct 6 ms 15196 KB Output is correct
10 Correct 6 ms 15276 KB Output is correct
11 Correct 7 ms 15452 KB Output is correct
12 Correct 7 ms 15452 KB Output is correct
13 Correct 6 ms 15448 KB Output is correct
14 Correct 6 ms 15348 KB Output is correct
15 Correct 6 ms 15332 KB Output is correct
16 Correct 9 ms 15452 KB Output is correct
17 Correct 8 ms 15452 KB Output is correct
18 Correct 7 ms 15452 KB Output is correct
19 Correct 8 ms 15196 KB Output is correct
20 Correct 8 ms 15268 KB Output is correct
21 Correct 7 ms 15196 KB Output is correct
22 Correct 7 ms 15452 KB Output is correct
23 Correct 6 ms 15452 KB Output is correct
24 Correct 7 ms 15196 KB Output is correct
25 Correct 8 ms 15196 KB Output is correct
26 Correct 8 ms 15196 KB Output is correct
27 Correct 7 ms 15448 KB Output is correct
28 Correct 8 ms 15452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15320 KB Output is correct
2 Correct 2645 ms 577268 KB Output is correct
3 Correct 1620 ms 578492 KB Output is correct
4 Correct 2854 ms 589136 KB Output is correct
5 Correct 2067 ms 578248 KB Output is correct
6 Correct 1405 ms 577736 KB Output is correct
7 Correct 1516 ms 578348 KB Output is correct
8 Correct 1307 ms 578752 KB Output is correct
9 Execution timed out 4001 ms 595028 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15320 KB Output is correct
2 Correct 2645 ms 577268 KB Output is correct
3 Correct 1620 ms 578492 KB Output is correct
4 Correct 2854 ms 589136 KB Output is correct
5 Correct 2067 ms 578248 KB Output is correct
6 Correct 1405 ms 577736 KB Output is correct
7 Correct 1516 ms 578348 KB Output is correct
8 Correct 1307 ms 578752 KB Output is correct
9 Execution timed out 4001 ms 595028 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 20000 KB Output is correct
2 Execution timed out 4115 ms 591848 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 20060 KB Output is correct
2 Execution timed out 4049 ms 588036 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15192 KB Output is correct
2 Correct 6 ms 15196 KB Output is correct
3 Correct 10 ms 15272 KB Output is correct
4 Correct 10 ms 18008 KB Output is correct
5 Correct 10 ms 18012 KB Output is correct
6 Correct 10 ms 18012 KB Output is correct
7 Correct 11 ms 18012 KB Output is correct
8 Correct 11 ms 18008 KB Output is correct
9 Correct 6 ms 15196 KB Output is correct
10 Correct 6 ms 15276 KB Output is correct
11 Correct 7 ms 15452 KB Output is correct
12 Correct 7 ms 15452 KB Output is correct
13 Correct 6 ms 15448 KB Output is correct
14 Correct 6 ms 15348 KB Output is correct
15 Correct 6 ms 15332 KB Output is correct
16 Correct 9 ms 15452 KB Output is correct
17 Correct 8 ms 15452 KB Output is correct
18 Correct 7 ms 15452 KB Output is correct
19 Correct 8 ms 15196 KB Output is correct
20 Correct 8 ms 15268 KB Output is correct
21 Correct 7 ms 15196 KB Output is correct
22 Correct 7 ms 15452 KB Output is correct
23 Correct 6 ms 15452 KB Output is correct
24 Correct 7 ms 15196 KB Output is correct
25 Correct 8 ms 15196 KB Output is correct
26 Correct 8 ms 15196 KB Output is correct
27 Correct 7 ms 15448 KB Output is correct
28 Correct 8 ms 15452 KB Output is correct
29 Correct 8 ms 15320 KB Output is correct
30 Correct 2645 ms 577268 KB Output is correct
31 Correct 1620 ms 578492 KB Output is correct
32 Correct 2854 ms 589136 KB Output is correct
33 Correct 2067 ms 578248 KB Output is correct
34 Correct 1405 ms 577736 KB Output is correct
35 Correct 1516 ms 578348 KB Output is correct
36 Correct 1307 ms 578752 KB Output is correct
37 Execution timed out 4001 ms 595028 KB Time limit exceeded
38 Halted 0 ms 0 KB -