답안 #1052144

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1052144 2024-08-10T12:06:18 Z VMaksimoski008 Vinjete (COI22_vinjete) C++17
56 / 100
127 ms 20108 KB
#include <bits/stdc++.h>
//#define int long long

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const int seg_sz = 5e6+5;

struct SegTree {
    int n;
    vector<pii> tree;
    vector<int> lazy;

    void init(int _n) {
        n = _n;
        tree.resize(4*_n+5);
        lazy.resize(4*_n+5);
        build(1, 1, n);
    }

    pii merge(pii a, pii b) {
        if(a.first < b.first) return a;
        if(a.first > b.first) return b;
        return { a.first, a.second + b.second };
    }

    void build(int u, int tl, int tr) {
        if(tl == tr) {
            tree[u].second = tr - tl + 1;
        } else {
            int tm = (tl + tr) / 2;
            build(2*u, tl, tm);
            build(2*u+1, tm+1, tr);
            tree[u] = merge(tree[2*u], tree[2*u+1]);
        }
    }

    void push(int u, int tl, int tr) {
        if(!lazy[u]) return ;
        tree[u].first += lazy[u];

        if(tl != tr) {
            lazy[2*u] += lazy[u];
            lazy[2*u+1] += lazy[u];
        }

        lazy[u] = 0;
    }

    void update(int u, int tl, int tr, int l, int r, int v) {
        push(u, tl, tr);
        if(tl > tr || l > tr || tl > r) return ;

        if(l <= tl && tr <= r) {
            lazy[u] += v;
            push(u, tl, tr);
            return ;
        }

        int tm = (tl + tr) / 2;
        update(2*u, tl, tm, l, r, v);
        update(2*u+1, tm+1, tr, l, r, v);
        tree[u] = merge(tree[2*u], tree[2*u+1]);
    }

    void update(int l, int r, int v) { update(1, 1, n, l, r, v); }

    pii query() {
        push(1, 1, n);
        return tree[1];
    }
} tree;

int m;
vector<array<int, 3> > graph[maxn];
vector<int> ans(maxn);

void dfs(int u, int p) {
    if(tree.query().first == 0) ans[u] = m - tree.query().second;
    else ans[u] = m;

    for(auto &[v, l, r] : graph[u]) {
        if(v == p) continue;
        tree.update(l, r, 1);
        dfs(v, u);
        tree.update(l, r, -1);
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);

    int n;
    cin >> n >> m;
    tree.init(m);

    for(int i=0; i<n-1; i++) {
        int a, b, l, r;
        cin >> a >> b >> l >> r;
        graph[a].push_back({ b, l, r });
        graph[b].push_back({ a, l, r });
    }
    
    dfs(1, 1);
    for(int i=2; i<=n; i++) cout << ans[i] << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3160 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 1 ms 3164 KB Output is correct
5 Correct 1 ms 3164 KB Output is correct
6 Correct 1 ms 3164 KB Output is correct
7 Correct 1 ms 3164 KB Output is correct
8 Correct 1 ms 3164 KB Output is correct
9 Correct 1 ms 3164 KB Output is correct
10 Correct 1 ms 3164 KB Output is correct
11 Correct 1 ms 3164 KB Output is correct
12 Correct 2 ms 3164 KB Output is correct
13 Correct 1 ms 3228 KB Output is correct
14 Correct 1 ms 3164 KB Output is correct
15 Correct 1 ms 3164 KB Output is correct
16 Correct 1 ms 3164 KB Output is correct
17 Correct 1 ms 3164 KB Output is correct
18 Correct 1 ms 3224 KB Output is correct
19 Correct 1 ms 3164 KB Output is correct
20 Correct 2 ms 3164 KB Output is correct
21 Correct 1 ms 3164 KB Output is correct
22 Correct 1 ms 3164 KB Output is correct
23 Correct 1 ms 3164 KB Output is correct
24 Correct 1 ms 3164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3160 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 1 ms 3164 KB Output is correct
5 Correct 1 ms 3164 KB Output is correct
6 Correct 1 ms 3164 KB Output is correct
7 Correct 1 ms 3164 KB Output is correct
8 Correct 1 ms 3164 KB Output is correct
9 Correct 1 ms 3164 KB Output is correct
10 Correct 1 ms 3164 KB Output is correct
11 Correct 1 ms 3164 KB Output is correct
12 Correct 2 ms 3164 KB Output is correct
13 Correct 1 ms 3228 KB Output is correct
14 Correct 1 ms 3164 KB Output is correct
15 Correct 1 ms 3164 KB Output is correct
16 Correct 1 ms 3164 KB Output is correct
17 Correct 1 ms 3164 KB Output is correct
18 Correct 1 ms 3224 KB Output is correct
19 Correct 1 ms 3164 KB Output is correct
20 Correct 2 ms 3164 KB Output is correct
21 Correct 1 ms 3164 KB Output is correct
22 Correct 1 ms 3164 KB Output is correct
23 Correct 1 ms 3164 KB Output is correct
24 Correct 1 ms 3164 KB Output is correct
25 Runtime error 4 ms 6236 KB Execution killed with signal 6
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3160 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 1 ms 3164 KB Output is correct
5 Correct 1 ms 3164 KB Output is correct
6 Correct 1 ms 3164 KB Output is correct
7 Correct 1 ms 3164 KB Output is correct
8 Correct 1 ms 3164 KB Output is correct
9 Correct 1 ms 3164 KB Output is correct
10 Correct 1 ms 3164 KB Output is correct
11 Correct 1 ms 3164 KB Output is correct
12 Correct 2 ms 3164 KB Output is correct
13 Correct 1 ms 3228 KB Output is correct
14 Correct 1 ms 3164 KB Output is correct
15 Correct 1 ms 3164 KB Output is correct
16 Correct 1 ms 3164 KB Output is correct
17 Correct 1 ms 3164 KB Output is correct
18 Correct 1 ms 3224 KB Output is correct
19 Correct 1 ms 3164 KB Output is correct
20 Correct 2 ms 3164 KB Output is correct
21 Correct 1 ms 3164 KB Output is correct
22 Correct 1 ms 3164 KB Output is correct
23 Correct 1 ms 3164 KB Output is correct
24 Correct 1 ms 3164 KB Output is correct
25 Correct 35 ms 9628 KB Output is correct
26 Correct 35 ms 9812 KB Output is correct
27 Correct 43 ms 9816 KB Output is correct
28 Correct 44 ms 9812 KB Output is correct
29 Correct 27 ms 9812 KB Output is correct
30 Correct 27 ms 9820 KB Output is correct
31 Correct 4 ms 5468 KB Output is correct
32 Correct 4 ms 5468 KB Output is correct
33 Correct 4 ms 5468 KB Output is correct
34 Correct 4 ms 5720 KB Output is correct
35 Correct 35 ms 7796 KB Output is correct
36 Correct 35 ms 8028 KB Output is correct
37 Correct 46 ms 8020 KB Output is correct
38 Correct 45 ms 7992 KB Output is correct
39 Correct 27 ms 8028 KB Output is correct
40 Correct 26 ms 7772 KB Output is correct
41 Correct 4 ms 5212 KB Output is correct
42 Correct 4 ms 5212 KB Output is correct
43 Correct 36 ms 7584 KB Output is correct
44 Correct 37 ms 7764 KB Output is correct
45 Correct 44 ms 7764 KB Output is correct
46 Correct 42 ms 7724 KB Output is correct
47 Correct 26 ms 7772 KB Output is correct
48 Correct 27 ms 7684 KB Output is correct
49 Correct 5 ms 5212 KB Output is correct
50 Correct 5 ms 5412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3160 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 1 ms 3164 KB Output is correct
5 Correct 1 ms 3164 KB Output is correct
6 Correct 1 ms 3164 KB Output is correct
7 Correct 1 ms 3164 KB Output is correct
8 Correct 1 ms 3164 KB Output is correct
9 Correct 1 ms 3164 KB Output is correct
10 Correct 1 ms 3164 KB Output is correct
11 Correct 1 ms 3164 KB Output is correct
12 Correct 2 ms 3164 KB Output is correct
13 Correct 1 ms 3228 KB Output is correct
14 Correct 1 ms 3164 KB Output is correct
15 Correct 1 ms 3164 KB Output is correct
16 Correct 1 ms 3164 KB Output is correct
17 Correct 1 ms 3164 KB Output is correct
18 Correct 1 ms 3224 KB Output is correct
19 Correct 1 ms 3164 KB Output is correct
20 Correct 2 ms 3164 KB Output is correct
21 Correct 1 ms 3164 KB Output is correct
22 Correct 1 ms 3164 KB Output is correct
23 Correct 1 ms 3164 KB Output is correct
24 Correct 1 ms 3164 KB Output is correct
25 Correct 35 ms 9628 KB Output is correct
26 Correct 35 ms 9812 KB Output is correct
27 Correct 43 ms 9816 KB Output is correct
28 Correct 44 ms 9812 KB Output is correct
29 Correct 27 ms 9812 KB Output is correct
30 Correct 27 ms 9820 KB Output is correct
31 Correct 4 ms 5468 KB Output is correct
32 Correct 4 ms 5468 KB Output is correct
33 Correct 4 ms 5468 KB Output is correct
34 Correct 4 ms 5720 KB Output is correct
35 Correct 35 ms 7796 KB Output is correct
36 Correct 35 ms 8028 KB Output is correct
37 Correct 46 ms 8020 KB Output is correct
38 Correct 45 ms 7992 KB Output is correct
39 Correct 27 ms 8028 KB Output is correct
40 Correct 26 ms 7772 KB Output is correct
41 Correct 4 ms 5212 KB Output is correct
42 Correct 4 ms 5212 KB Output is correct
43 Correct 36 ms 7584 KB Output is correct
44 Correct 37 ms 7764 KB Output is correct
45 Correct 44 ms 7764 KB Output is correct
46 Correct 42 ms 7724 KB Output is correct
47 Correct 26 ms 7772 KB Output is correct
48 Correct 27 ms 7684 KB Output is correct
49 Correct 5 ms 5212 KB Output is correct
50 Correct 5 ms 5412 KB Output is correct
51 Correct 93 ms 19792 KB Output is correct
52 Correct 101 ms 19796 KB Output is correct
53 Correct 127 ms 20036 KB Output is correct
54 Correct 119 ms 20052 KB Output is correct
55 Correct 71 ms 20108 KB Output is correct
56 Correct 71 ms 20108 KB Output is correct
57 Correct 15 ms 10332 KB Output is correct
58 Correct 15 ms 10332 KB Output is correct
59 Correct 18 ms 10332 KB Output is correct
60 Correct 14 ms 10332 KB Output is correct
61 Correct 98 ms 15272 KB Output is correct
62 Correct 97 ms 15444 KB Output is correct
63 Correct 121 ms 15188 KB Output is correct
64 Correct 114 ms 15320 KB Output is correct
65 Correct 75 ms 15324 KB Output is correct
66 Correct 69 ms 15204 KB Output is correct
67 Correct 15 ms 9308 KB Output is correct
68 Correct 14 ms 9308 KB Output is correct
69 Correct 97 ms 14532 KB Output is correct
70 Correct 95 ms 14676 KB Output is correct
71 Correct 112 ms 14932 KB Output is correct
72 Correct 118 ms 14932 KB Output is correct
73 Correct 80 ms 14700 KB Output is correct
74 Correct 77 ms 14676 KB Output is correct
75 Correct 15 ms 9052 KB Output is correct
76 Correct 16 ms 9208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3160 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 1 ms 3164 KB Output is correct
5 Correct 1 ms 3164 KB Output is correct
6 Correct 1 ms 3164 KB Output is correct
7 Correct 1 ms 3164 KB Output is correct
8 Correct 1 ms 3164 KB Output is correct
9 Correct 1 ms 3164 KB Output is correct
10 Correct 1 ms 3164 KB Output is correct
11 Correct 1 ms 3164 KB Output is correct
12 Correct 2 ms 3164 KB Output is correct
13 Correct 1 ms 3228 KB Output is correct
14 Correct 1 ms 3164 KB Output is correct
15 Correct 1 ms 3164 KB Output is correct
16 Correct 1 ms 3164 KB Output is correct
17 Correct 1 ms 3164 KB Output is correct
18 Correct 1 ms 3224 KB Output is correct
19 Correct 1 ms 3164 KB Output is correct
20 Correct 2 ms 3164 KB Output is correct
21 Correct 1 ms 3164 KB Output is correct
22 Correct 1 ms 3164 KB Output is correct
23 Correct 1 ms 3164 KB Output is correct
24 Correct 1 ms 3164 KB Output is correct
25 Runtime error 4 ms 6236 KB Execution killed with signal 6
26 Halted 0 ms 0 KB -