Submission #1003665

# Submission time Handle Problem Language Result Execution time Memory
1003665 2024-06-20T14:53:01 Z onbert Sprinkler (JOI22_sprinkler) C++17
41 / 100
4000 ms 180844 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 2e5 + 5, maxN = 8e5 + 5, m = 43;
int n, M;
vector<int> adj[maxn];
int newid[maxn], d[maxn], fa[maxn], a[maxn];
bool vis[maxn];

pair<int,int> range[maxn][m];
void dfs(int u) {
    range[u][0] = {newid[u], newid[u]};
    if (adj[u].size() == 0) return;
    for (int v:adj[u]) dfs(v);
    int sz = adj[u].size();
    int l = 0, r = sz - 1;
    for (int i=1;i<m;i++) {
        while (l < sz && range[adj[u][l]][i-1].first==-1) l++;
        while (r >= 0 && range[adj[u][r]][i-1].first==-1) r--;
        if (l>r) break;
        range[u][i] = {range[adj[u][l]][i-1].first, range[adj[u][r]][i-1].second};
    }
}

int seg[maxN];
void build(int id, int l, int r) {
    seg[id] = 1;
    if (l==r) {
        seg[id] = a[l];
        return;
    }
    int mid = (l+r)/2;
    build(id*2, l, mid); build(id*2+1, mid+1, r);
}
void update(int id, int l, int r, int findl, int findr, int val) {
    if (r<findl || findr<l) return;
    if (findl<=l && r<=findr) {
        seg[id] = seg[id] * val % M;
        return;
    }
    int mid = (l+r)/2;
    update(id*2, l, mid, findl, findr, val);
    update(id*2+1, mid+1, r, findl, findr, val);
}
int qry(int id, int l, int r, int target) {
    if (r<target || target<l) return 1;
    if (l==r) return seg[id];
    int mid = (l+r)/2;
    return (seg[id] * qry(id*2, l, mid, target) % M) * qry(id*2+1, mid+1, r, target) % M;
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> M;
    for (int i=1;i<=n-1;i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int A[n+1];
    for (int i=1;i<=n;i++) cin >> A[i];
    queue<int> Q;
    Q.push(1);
    vis[1] = true, d[1] = 0, fa[1] = -1;
    int cnter = 0;
    while (Q.size() > 0) {
        int u = Q.front();
        cnter++;
        newid[u] = cnter;
        for (int v:adj[u]) if (!vis[v]) {
            vis[v] = true, fa[v] = u, d[v] = d[u] + 1;
            adj[v].erase(find(adj[v].begin(), adj[v].end(), u));
            Q.push(v);
        }
        Q.pop();
    }
    for (int i=1;i<=n;i++) for (int j=0;j<m;j++) range[i][j] = {-1, -1};
    dfs(1);
    // for (int i=1;i<=n;i++) cout << newid[i] << " "; cout << endl;
    // for (int i=1;i<=n;i++) {
    //     cout << i << endl;
    //     for (int j=0;j<6;j++) cout << range[i][j].first << "." << range[i][j].second << " "; cout << endl;
    // }
    for (int i=1;i<=n;i++) a[newid[i]] = A[i];
    build(1, 1, n);
    int q;
    cin >> q;
    while (q--) {
        int t;
        cin >> t;
        if (t==1) {
            int x, D, w;
            cin >> x >> D >> w;
            int u = x;
            vector<int> vec;
            for (; u!=-1 && d[u] >= d[x] - D; u = fa[u]) vec.push_back(u);
            reverse(vec.begin(), vec.end());
            int dep = max(d[x] - D, (int)0);
            // cout << dep << endl;
            for (int v:vec) {
                while (dep - d[v] + d[x] - d[v] <= D) {
                    update(1, 1, n, range[v][dep-d[v]].first, range[v][dep-d[v]].second, w);
                    dep++;
                }
            }
        } else if (t==2) {
            int x;
            cin >> x;
            cout << qry(1, 1, n, newid[x]) << endl;
        }
        // for (int i=1;i<=n;i++) cout << qry(1, 1, n, newid[i]) << " "; cout << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 14684 KB Output is correct
3 Correct 2 ms 14840 KB Output is correct
4 Correct 5 ms 16988 KB Output is correct
5 Correct 3 ms 17016 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 3 ms 14684 KB Output is correct
10 Correct 3 ms 14684 KB Output is correct
11 Correct 3 ms 14864 KB Output is correct
12 Correct 3 ms 14680 KB Output is correct
13 Correct 2 ms 14684 KB Output is correct
14 Correct 2 ms 14684 KB Output is correct
15 Correct 3 ms 14684 KB Output is correct
16 Correct 3 ms 14684 KB Output is correct
17 Correct 2 ms 14684 KB Output is correct
18 Correct 2 ms 14680 KB Output is correct
19 Correct 2 ms 14684 KB Output is correct
20 Correct 3 ms 14684 KB Output is correct
21 Correct 2 ms 14684 KB Output is correct
22 Correct 2 ms 14684 KB Output is correct
23 Correct 2 ms 14684 KB Output is correct
24 Correct 3 ms 14684 KB Output is correct
25 Correct 3 ms 14684 KB Output is correct
26 Correct 3 ms 14684 KB Output is correct
27 Correct 2 ms 14684 KB Output is correct
28 Correct 2 ms 14876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 646 ms 172916 KB Output is correct
3 Correct 473 ms 173392 KB Output is correct
4 Correct 612 ms 178024 KB Output is correct
5 Correct 528 ms 173032 KB Output is correct
6 Correct 533 ms 173140 KB Output is correct
7 Correct 497 ms 173908 KB Output is correct
8 Correct 425 ms 175296 KB Output is correct
9 Correct 714 ms 180844 KB Output is correct
10 Correct 512 ms 180560 KB Output is correct
11 Correct 589 ms 172928 KB Output is correct
12 Correct 458 ms 173396 KB Output is correct
13 Correct 321 ms 175000 KB Output is correct
14 Correct 316 ms 174776 KB Output is correct
15 Correct 303 ms 173496 KB Output is correct
16 Correct 329 ms 174164 KB Output is correct
17 Correct 323 ms 174608 KB Output is correct
18 Correct 3 ms 14684 KB Output is correct
19 Correct 2 ms 14684 KB Output is correct
20 Correct 3 ms 14876 KB Output is correct
21 Correct 3 ms 14684 KB Output is correct
22 Correct 3 ms 14684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 646 ms 172916 KB Output is correct
3 Correct 473 ms 173392 KB Output is correct
4 Correct 612 ms 178024 KB Output is correct
5 Correct 528 ms 173032 KB Output is correct
6 Correct 533 ms 173140 KB Output is correct
7 Correct 497 ms 173908 KB Output is correct
8 Correct 425 ms 175296 KB Output is correct
9 Correct 714 ms 180844 KB Output is correct
10 Correct 512 ms 180560 KB Output is correct
11 Correct 589 ms 172928 KB Output is correct
12 Correct 458 ms 173396 KB Output is correct
13 Correct 321 ms 175000 KB Output is correct
14 Correct 316 ms 174776 KB Output is correct
15 Correct 303 ms 173496 KB Output is correct
16 Correct 329 ms 174164 KB Output is correct
17 Correct 323 ms 174608 KB Output is correct
18 Correct 3 ms 14684 KB Output is correct
19 Correct 2 ms 14684 KB Output is correct
20 Correct 3 ms 14876 KB Output is correct
21 Correct 3 ms 14684 KB Output is correct
22 Correct 3 ms 14684 KB Output is correct
23 Correct 2 ms 14684 KB Output is correct
24 Correct 682 ms 172840 KB Output is correct
25 Correct 600 ms 173400 KB Output is correct
26 Correct 719 ms 180708 KB Output is correct
27 Correct 637 ms 173004 KB Output is correct
28 Correct 595 ms 173540 KB Output is correct
29 Correct 509 ms 163668 KB Output is correct
30 Correct 465 ms 173312 KB Output is correct
31 Correct 713 ms 177236 KB Output is correct
32 Correct 665 ms 178164 KB Output is correct
33 Correct 674 ms 167736 KB Output is correct
34 Correct 521 ms 162128 KB Output is correct
35 Correct 2 ms 14680 KB Output is correct
36 Correct 2 ms 14684 KB Output is correct
37 Correct 2 ms 14684 KB Output is correct
38 Correct 3 ms 14884 KB Output is correct
39 Correct 2 ms 14684 KB Output is correct
40 Correct 2 ms 14684 KB Output is correct
41 Correct 2 ms 14684 KB Output is correct
42 Correct 2 ms 14684 KB Output is correct
43 Correct 2 ms 14684 KB Output is correct
44 Correct 2 ms 14684 KB Output is correct
45 Correct 3 ms 14872 KB Output is correct
46 Correct 3 ms 14680 KB Output is correct
47 Correct 2 ms 14680 KB Output is correct
48 Correct 2 ms 14876 KB Output is correct
49 Correct 2 ms 14684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 1142 ms 170148 KB Output is correct
3 Execution timed out 4077 ms 175920 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 1164 ms 173624 KB Output is correct
3 Execution timed out 4011 ms 171600 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 14684 KB Output is correct
3 Correct 2 ms 14840 KB Output is correct
4 Correct 5 ms 16988 KB Output is correct
5 Correct 3 ms 17016 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 3 ms 14684 KB Output is correct
10 Correct 3 ms 14684 KB Output is correct
11 Correct 3 ms 14864 KB Output is correct
12 Correct 3 ms 14680 KB Output is correct
13 Correct 2 ms 14684 KB Output is correct
14 Correct 2 ms 14684 KB Output is correct
15 Correct 3 ms 14684 KB Output is correct
16 Correct 3 ms 14684 KB Output is correct
17 Correct 2 ms 14684 KB Output is correct
18 Correct 2 ms 14680 KB Output is correct
19 Correct 2 ms 14684 KB Output is correct
20 Correct 3 ms 14684 KB Output is correct
21 Correct 2 ms 14684 KB Output is correct
22 Correct 2 ms 14684 KB Output is correct
23 Correct 2 ms 14684 KB Output is correct
24 Correct 3 ms 14684 KB Output is correct
25 Correct 3 ms 14684 KB Output is correct
26 Correct 3 ms 14684 KB Output is correct
27 Correct 2 ms 14684 KB Output is correct
28 Correct 2 ms 14876 KB Output is correct
29 Correct 2 ms 14684 KB Output is correct
30 Correct 646 ms 172916 KB Output is correct
31 Correct 473 ms 173392 KB Output is correct
32 Correct 612 ms 178024 KB Output is correct
33 Correct 528 ms 173032 KB Output is correct
34 Correct 533 ms 173140 KB Output is correct
35 Correct 497 ms 173908 KB Output is correct
36 Correct 425 ms 175296 KB Output is correct
37 Correct 714 ms 180844 KB Output is correct
38 Correct 512 ms 180560 KB Output is correct
39 Correct 589 ms 172928 KB Output is correct
40 Correct 458 ms 173396 KB Output is correct
41 Correct 321 ms 175000 KB Output is correct
42 Correct 316 ms 174776 KB Output is correct
43 Correct 303 ms 173496 KB Output is correct
44 Correct 329 ms 174164 KB Output is correct
45 Correct 323 ms 174608 KB Output is correct
46 Correct 3 ms 14684 KB Output is correct
47 Correct 2 ms 14684 KB Output is correct
48 Correct 3 ms 14876 KB Output is correct
49 Correct 3 ms 14684 KB Output is correct
50 Correct 3 ms 14684 KB Output is correct
51 Correct 2 ms 14684 KB Output is correct
52 Correct 682 ms 172840 KB Output is correct
53 Correct 600 ms 173400 KB Output is correct
54 Correct 719 ms 180708 KB Output is correct
55 Correct 637 ms 173004 KB Output is correct
56 Correct 595 ms 173540 KB Output is correct
57 Correct 509 ms 163668 KB Output is correct
58 Correct 465 ms 173312 KB Output is correct
59 Correct 713 ms 177236 KB Output is correct
60 Correct 665 ms 178164 KB Output is correct
61 Correct 674 ms 167736 KB Output is correct
62 Correct 521 ms 162128 KB Output is correct
63 Correct 2 ms 14680 KB Output is correct
64 Correct 2 ms 14684 KB Output is correct
65 Correct 2 ms 14684 KB Output is correct
66 Correct 3 ms 14884 KB Output is correct
67 Correct 2 ms 14684 KB Output is correct
68 Correct 2 ms 14684 KB Output is correct
69 Correct 2 ms 14684 KB Output is correct
70 Correct 2 ms 14684 KB Output is correct
71 Correct 2 ms 14684 KB Output is correct
72 Correct 2 ms 14684 KB Output is correct
73 Correct 3 ms 14872 KB Output is correct
74 Correct 3 ms 14680 KB Output is correct
75 Correct 2 ms 14680 KB Output is correct
76 Correct 2 ms 14876 KB Output is correct
77 Correct 2 ms 14684 KB Output is correct
78 Correct 2 ms 14684 KB Output is correct
79 Correct 1142 ms 170148 KB Output is correct
80 Execution timed out 4077 ms 175920 KB Time limit exceeded
81 Halted 0 ms 0 KB -