Submission #850593

# Submission time Handle Problem Language Result Execution time Memory
850593 2023-09-17T04:41:56 Z Cyanmond Vinjete (COI22_vinjete) C++17
100 / 100
193 ms 35468 KB
#include <bits/stdc++.h>

using namespace std;

#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define per(i, l, r) for (int i = (r - 1); i >= l; --i)
#define ALL(x) (x).begin(), (x).end()

using i64 = long long;

struct Node {
    i64 len;
    i64 sum;
    i64 cnt;
};

void merge(Node &p, Node &a, Node &b) {
    p.len = a.len + b.len;
    p.sum = (a.cnt >= 1 ? a.len : a.sum) + (b.cnt >= 1 ? b.len : b.sum);
}

void ap(Node &nd, int v) {
    nd.cnt += v;
    
}

Node id() {
    return {0, 0, 0};
}

struct UnionSeg {
    int n, siz, lg;
    vector<Node> data;

    UnionSeg(int n_) : n(n_) {
        lg = 0;
        while ((1 << lg) < n) ++lg;
        siz = 1 << lg;
        data.assign(2 * siz, id());
    }

    void affine(int i, const Node &nd) {
        i += siz;
        data[i] = nd;
        while (i != 1) {
            i /= 2;
            merge(data[i], data[2 * i], data[2 * i + 1]);
        }
    }

    void apply(int l, int r, int v) {
        l += siz, r += siz;
        int l2 = l, r2 = r;
        for (; l < r; l /= 2, r /= 2) {
            if (l & 1) {
                data[l].cnt += v;
                ++l;
            }
            if (r & 1) {
                --r;
                data[r].cnt += v;
            }
        }
        l = l2, r = r2;
        for (int i = 1; i <= lg; ++i) {
            merge(data[l >> i], data[2 * (l >> i)], data[2 * (l >> i) + 1]);
            merge(data[(r - 1) >> i], data[2 * ((r - 1) >> i)], data[2 * ((r - 1) >> i) + 1]);
        }
    }

    i64 sum() {
        return data[1].cnt >= 1 ? data[1].len : data[1].sum;
    }
};

void main_() {
    int N;
    i64 M;
    cin >> N >> M;
    vector<vector<tuple<int, i64, i64>>> Tree(N);
    vector<i64> vals;
    rep(i, 0, N - 1) {
        int a, b, l, r;
        cin >> a >> b >> l >> r;
        --a, --b;
        --l;
        Tree[a].push_back({b, l, r});
        Tree[b].push_back({a, l, r});
        vals.push_back(l);
        vals.push_back(r);
    }
    sort(ALL(vals));
    vals.erase(unique(ALL(vals)), vals.end());

    const int X = (int)vals.size();
    UnionSeg seg(X - 1);
    rep(i, 0, X - 1) {
        seg.affine(i, {vals[i + 1] - vals[i], 0, 0});
    }

    vector<i64> ans(N);
    auto dfs = [&](auto &&self, const int v, const int p) -> void {
        ans[v] = seg.sum();
        for (const auto &[t, l, r] : Tree[v]) {
            if (t == p) continue;
            const int a = (int)(lower_bound(ALL(vals), l) - vals.begin());
            const int b = (int)(lower_bound(ALL(vals), r) - vals.begin());
            seg.apply(a, b, 1);
            self(self, t, v);
            seg.apply(a, b, -1);
        }
    };
    dfs(dfs, 0, -1);

    rep(i, 1, N) cout << ans[i] << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    main_();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 472 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 472 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 1 ms 860 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 564 KB Output is correct
32 Correct 1 ms 564 KB Output is correct
33 Correct 2 ms 756 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 1 ms 608 KB Output is correct
39 Correct 1 ms 856 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 600 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 2 ms 604 KB Output is correct
47 Correct 1 ms 612 KB Output is correct
48 Correct 2 ms 856 KB Output is correct
49 Correct 1 ms 608 KB Output is correct
50 Correct 2 ms 616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 472 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 31 ms 8912 KB Output is correct
26 Correct 32 ms 8908 KB Output is correct
27 Correct 47 ms 10436 KB Output is correct
28 Correct 49 ms 10564 KB Output is correct
29 Correct 41 ms 11976 KB Output is correct
30 Correct 41 ms 12092 KB Output is correct
31 Correct 5 ms 2140 KB Output is correct
32 Correct 4 ms 2140 KB Output is correct
33 Correct 6 ms 2140 KB Output is correct
34 Correct 5 ms 2140 KB Output is correct
35 Correct 33 ms 6048 KB Output is correct
36 Correct 34 ms 6344 KB Output is correct
37 Correct 50 ms 7680 KB Output is correct
38 Correct 55 ms 8092 KB Output is correct
39 Correct 46 ms 9416 KB Output is correct
40 Correct 46 ms 9156 KB Output is correct
41 Correct 5 ms 1880 KB Output is correct
42 Correct 5 ms 1884 KB Output is correct
43 Correct 32 ms 5844 KB Output is correct
44 Correct 32 ms 5756 KB Output is correct
45 Correct 54 ms 7620 KB Output is correct
46 Correct 54 ms 7520 KB Output is correct
47 Correct 43 ms 8848 KB Output is correct
48 Correct 50 ms 8904 KB Output is correct
49 Correct 5 ms 1884 KB Output is correct
50 Correct 5 ms 1864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 472 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 31 ms 8912 KB Output is correct
26 Correct 32 ms 8908 KB Output is correct
27 Correct 47 ms 10436 KB Output is correct
28 Correct 49 ms 10564 KB Output is correct
29 Correct 41 ms 11976 KB Output is correct
30 Correct 41 ms 12092 KB Output is correct
31 Correct 5 ms 2140 KB Output is correct
32 Correct 4 ms 2140 KB Output is correct
33 Correct 6 ms 2140 KB Output is correct
34 Correct 5 ms 2140 KB Output is correct
35 Correct 33 ms 6048 KB Output is correct
36 Correct 34 ms 6344 KB Output is correct
37 Correct 50 ms 7680 KB Output is correct
38 Correct 55 ms 8092 KB Output is correct
39 Correct 46 ms 9416 KB Output is correct
40 Correct 46 ms 9156 KB Output is correct
41 Correct 5 ms 1880 KB Output is correct
42 Correct 5 ms 1884 KB Output is correct
43 Correct 32 ms 5844 KB Output is correct
44 Correct 32 ms 5756 KB Output is correct
45 Correct 54 ms 7620 KB Output is correct
46 Correct 54 ms 7520 KB Output is correct
47 Correct 43 ms 8848 KB Output is correct
48 Correct 50 ms 8904 KB Output is correct
49 Correct 5 ms 1884 KB Output is correct
50 Correct 5 ms 1864 KB Output is correct
51 Correct 79 ms 21508 KB Output is correct
52 Correct 75 ms 21564 KB Output is correct
53 Correct 137 ms 28356 KB Output is correct
54 Correct 139 ms 28296 KB Output is correct
55 Correct 108 ms 27832 KB Output is correct
56 Correct 115 ms 27864 KB Output is correct
57 Correct 17 ms 6096 KB Output is correct
58 Correct 17 ms 6096 KB Output is correct
59 Correct 17 ms 6096 KB Output is correct
60 Correct 18 ms 6152 KB Output is correct
61 Correct 79 ms 15044 KB Output is correct
62 Correct 98 ms 15144 KB Output is correct
63 Correct 149 ms 21644 KB Output is correct
64 Correct 162 ms 21448 KB Output is correct
65 Correct 131 ms 21440 KB Output is correct
66 Correct 163 ms 21152 KB Output is correct
67 Correct 17 ms 4820 KB Output is correct
68 Correct 17 ms 4900 KB Output is correct
69 Correct 99 ms 14008 KB Output is correct
70 Correct 84 ms 14000 KB Output is correct
71 Correct 165 ms 20620 KB Output is correct
72 Correct 160 ms 20656 KB Output is correct
73 Correct 123 ms 20096 KB Output is correct
74 Correct 143 ms 19972 KB Output is correct
75 Correct 21 ms 4564 KB Output is correct
76 Correct 20 ms 4564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 472 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 1 ms 860 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 564 KB Output is correct
32 Correct 1 ms 564 KB Output is correct
33 Correct 2 ms 756 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 1 ms 608 KB Output is correct
39 Correct 1 ms 856 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 600 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 2 ms 604 KB Output is correct
47 Correct 1 ms 612 KB Output is correct
48 Correct 2 ms 856 KB Output is correct
49 Correct 1 ms 608 KB Output is correct
50 Correct 2 ms 616 KB Output is correct
51 Correct 31 ms 8912 KB Output is correct
52 Correct 32 ms 8908 KB Output is correct
53 Correct 47 ms 10436 KB Output is correct
54 Correct 49 ms 10564 KB Output is correct
55 Correct 41 ms 11976 KB Output is correct
56 Correct 41 ms 12092 KB Output is correct
57 Correct 5 ms 2140 KB Output is correct
58 Correct 4 ms 2140 KB Output is correct
59 Correct 6 ms 2140 KB Output is correct
60 Correct 5 ms 2140 KB Output is correct
61 Correct 33 ms 6048 KB Output is correct
62 Correct 34 ms 6344 KB Output is correct
63 Correct 50 ms 7680 KB Output is correct
64 Correct 55 ms 8092 KB Output is correct
65 Correct 46 ms 9416 KB Output is correct
66 Correct 46 ms 9156 KB Output is correct
67 Correct 5 ms 1880 KB Output is correct
68 Correct 5 ms 1884 KB Output is correct
69 Correct 32 ms 5844 KB Output is correct
70 Correct 32 ms 5756 KB Output is correct
71 Correct 54 ms 7620 KB Output is correct
72 Correct 54 ms 7520 KB Output is correct
73 Correct 43 ms 8848 KB Output is correct
74 Correct 50 ms 8904 KB Output is correct
75 Correct 5 ms 1884 KB Output is correct
76 Correct 5 ms 1864 KB Output is correct
77 Correct 79 ms 21508 KB Output is correct
78 Correct 75 ms 21564 KB Output is correct
79 Correct 137 ms 28356 KB Output is correct
80 Correct 139 ms 28296 KB Output is correct
81 Correct 108 ms 27832 KB Output is correct
82 Correct 115 ms 27864 KB Output is correct
83 Correct 17 ms 6096 KB Output is correct
84 Correct 17 ms 6096 KB Output is correct
85 Correct 17 ms 6096 KB Output is correct
86 Correct 18 ms 6152 KB Output is correct
87 Correct 79 ms 15044 KB Output is correct
88 Correct 98 ms 15144 KB Output is correct
89 Correct 149 ms 21644 KB Output is correct
90 Correct 162 ms 21448 KB Output is correct
91 Correct 131 ms 21440 KB Output is correct
92 Correct 163 ms 21152 KB Output is correct
93 Correct 17 ms 4820 KB Output is correct
94 Correct 17 ms 4900 KB Output is correct
95 Correct 99 ms 14008 KB Output is correct
96 Correct 84 ms 14000 KB Output is correct
97 Correct 165 ms 20620 KB Output is correct
98 Correct 160 ms 20656 KB Output is correct
99 Correct 123 ms 20096 KB Output is correct
100 Correct 143 ms 19972 KB Output is correct
101 Correct 21 ms 4564 KB Output is correct
102 Correct 20 ms 4564 KB Output is correct
103 Correct 80 ms 22412 KB Output is correct
104 Correct 78 ms 22468 KB Output is correct
105 Correct 163 ms 35376 KB Output is correct
106 Correct 163 ms 35468 KB Output is correct
107 Correct 132 ms 35012 KB Output is correct
108 Correct 130 ms 35008 KB Output is correct
109 Correct 19 ms 7880 KB Output is correct
110 Correct 19 ms 7880 KB Output is correct
111 Correct 20 ms 7892 KB Output is correct
112 Correct 19 ms 7940 KB Output is correct
113 Correct 88 ms 16260 KB Output is correct
114 Correct 95 ms 16316 KB Output is correct
115 Correct 175 ms 28972 KB Output is correct
116 Correct 184 ms 29004 KB Output is correct
117 Correct 140 ms 28356 KB Output is correct
118 Correct 158 ms 28348 KB Output is correct
119 Correct 19 ms 6612 KB Output is correct
120 Correct 19 ms 6608 KB Output is correct
121 Correct 87 ms 14944 KB Output is correct
122 Correct 107 ms 14872 KB Output is correct
123 Correct 193 ms 28096 KB Output is correct
124 Correct 189 ms 28072 KB Output is correct
125 Correct 180 ms 27348 KB Output is correct
126 Correct 152 ms 27328 KB Output is correct
127 Correct 21 ms 6356 KB Output is correct
128 Correct 22 ms 6420 KB Output is correct