Submission #1052169

# Submission time Handle Problem Language Result Execution time Memory
1052169 2024-08-10T12:13:33 Z VMaksimoski008 Vinjete (COI22_vinjete) C++17
100 / 100
519 ms 119072 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, id=2;
    vector<pii> tree;
    vector<int> lazy, L, R;
 
    SegTree(int _n) : n(_n), tree(seg_sz), lazy(seg_sz), L(seg_sz), R(seg_sz) {
        tree[1] = { 0, n };
    }
 
    void init(int n2) {
        n = n2;
        tree[1] = { 0, 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 push(int u, int tl, int tr) {
        if(!lazy[u]) return ;
        tree[u].first += lazy[u];
 
        if(tl != tr) {
            if(L[u]) lazy[L[u]] += lazy[u];
            if(R[u]) lazy[R[u]] += 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;
        if(L[u]) update(L[u], tl, tm, l, r, v);
        if(R[u]) update(R[u], tm+1, tr, l, r, v);
        tree[u] = merge(tree[L[u]], tree[R[u]]);
    }
 
    void add(int u, int tl, int tr, int l, int r) {
        if(tl > tr || l > tr || tl > r) return ;
        if(l <= tl && tr <= r) return ;
 
        int tm = (tl + tr) / 2;
        if(L[u] == 0) {
            L[u] = id++;
            tree[L[u]] = { tree[u].first, tm - tl + 1 };
        }
 
        if(R[u] == 0) {
            R[u] = id++;
            tree[R[u]] = { tree[u].first, tr - tm };
        }
 
        add(L[u], tl, tm, l, r);
        add(R[u], tm+1, tr, l, r);
    }
 
    pii query() {
        push(1, 1, n);
        return tree[1];
    }
 
    void update(int l, int r, int v) { 
        add(1, 1, n, l, r);
        update(1, 1, n, l, r, v);
    }
} tree(1e9);
 
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;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 100956 KB Output is correct
2 Correct 14 ms 101172 KB Output is correct
3 Correct 14 ms 101108 KB Output is correct
4 Correct 14 ms 101192 KB Output is correct
5 Correct 14 ms 100984 KB Output is correct
6 Correct 12 ms 101168 KB Output is correct
7 Correct 13 ms 100956 KB Output is correct
8 Correct 12 ms 101064 KB Output is correct
9 Correct 18 ms 101012 KB Output is correct
10 Correct 16 ms 100984 KB Output is correct
11 Correct 13 ms 100976 KB Output is correct
12 Correct 13 ms 101064 KB Output is correct
13 Correct 14 ms 101096 KB Output is correct
14 Correct 13 ms 100956 KB Output is correct
15 Correct 16 ms 100920 KB Output is correct
16 Correct 13 ms 100836 KB Output is correct
17 Correct 13 ms 101032 KB Output is correct
18 Correct 16 ms 100864 KB Output is correct
19 Correct 22 ms 101096 KB Output is correct
20 Correct 14 ms 100956 KB Output is correct
21 Correct 13 ms 100952 KB Output is correct
22 Correct 12 ms 100956 KB Output is correct
23 Correct 17 ms 100956 KB Output is correct
24 Correct 18 ms 100952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 100956 KB Output is correct
2 Correct 14 ms 101172 KB Output is correct
3 Correct 14 ms 101108 KB Output is correct
4 Correct 14 ms 101192 KB Output is correct
5 Correct 14 ms 100984 KB Output is correct
6 Correct 12 ms 101168 KB Output is correct
7 Correct 13 ms 100956 KB Output is correct
8 Correct 12 ms 101064 KB Output is correct
9 Correct 18 ms 101012 KB Output is correct
10 Correct 16 ms 100984 KB Output is correct
11 Correct 13 ms 100976 KB Output is correct
12 Correct 13 ms 101064 KB Output is correct
13 Correct 14 ms 101096 KB Output is correct
14 Correct 13 ms 100956 KB Output is correct
15 Correct 16 ms 100920 KB Output is correct
16 Correct 13 ms 100836 KB Output is correct
17 Correct 13 ms 101032 KB Output is correct
18 Correct 16 ms 100864 KB Output is correct
19 Correct 22 ms 101096 KB Output is correct
20 Correct 14 ms 100956 KB Output is correct
21 Correct 13 ms 100952 KB Output is correct
22 Correct 12 ms 100956 KB Output is correct
23 Correct 17 ms 100956 KB Output is correct
24 Correct 18 ms 100952 KB Output is correct
25 Correct 16 ms 101212 KB Output is correct
26 Correct 14 ms 101212 KB Output is correct
27 Correct 18 ms 101212 KB Output is correct
28 Correct 22 ms 101216 KB Output is correct
29 Correct 13 ms 101212 KB Output is correct
30 Correct 14 ms 101100 KB Output is correct
31 Correct 14 ms 101156 KB Output is correct
32 Correct 14 ms 101208 KB Output is correct
33 Correct 14 ms 101212 KB Output is correct
34 Correct 13 ms 101212 KB Output is correct
35 Correct 18 ms 101064 KB Output is correct
36 Correct 18 ms 100956 KB Output is correct
37 Correct 16 ms 101016 KB Output is correct
38 Correct 18 ms 101036 KB Output is correct
39 Correct 14 ms 100956 KB Output is correct
40 Correct 14 ms 101044 KB Output is correct
41 Correct 16 ms 100956 KB Output is correct
42 Correct 22 ms 100956 KB Output is correct
43 Correct 14 ms 100920 KB Output is correct
44 Correct 19 ms 100920 KB Output is correct
45 Correct 17 ms 100956 KB Output is correct
46 Correct 15 ms 101000 KB Output is correct
47 Correct 14 ms 101080 KB Output is correct
48 Correct 13 ms 101116 KB Output is correct
49 Correct 13 ms 100956 KB Output is correct
50 Correct 14 ms 101104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 100956 KB Output is correct
2 Correct 14 ms 101172 KB Output is correct
3 Correct 14 ms 101108 KB Output is correct
4 Correct 14 ms 101192 KB Output is correct
5 Correct 14 ms 100984 KB Output is correct
6 Correct 12 ms 101168 KB Output is correct
7 Correct 13 ms 100956 KB Output is correct
8 Correct 12 ms 101064 KB Output is correct
9 Correct 18 ms 101012 KB Output is correct
10 Correct 16 ms 100984 KB Output is correct
11 Correct 13 ms 100976 KB Output is correct
12 Correct 13 ms 101064 KB Output is correct
13 Correct 14 ms 101096 KB Output is correct
14 Correct 13 ms 100956 KB Output is correct
15 Correct 16 ms 100920 KB Output is correct
16 Correct 13 ms 100836 KB Output is correct
17 Correct 13 ms 101032 KB Output is correct
18 Correct 16 ms 100864 KB Output is correct
19 Correct 22 ms 101096 KB Output is correct
20 Correct 14 ms 100956 KB Output is correct
21 Correct 13 ms 100952 KB Output is correct
22 Correct 12 ms 100956 KB Output is correct
23 Correct 17 ms 100956 KB Output is correct
24 Correct 18 ms 100952 KB Output is correct
25 Correct 60 ms 106868 KB Output is correct
26 Correct 62 ms 106676 KB Output is correct
27 Correct 88 ms 106836 KB Output is correct
28 Correct 97 ms 106744 KB Output is correct
29 Correct 53 ms 106780 KB Output is correct
30 Correct 54 ms 106836 KB Output is correct
31 Correct 18 ms 101720 KB Output is correct
32 Correct 15 ms 101708 KB Output is correct
33 Correct 20 ms 101724 KB Output is correct
34 Correct 17 ms 101768 KB Output is correct
35 Correct 75 ms 103248 KB Output is correct
36 Correct 63 ms 103492 KB Output is correct
37 Correct 85 ms 103260 KB Output is correct
38 Correct 102 ms 103520 KB Output is correct
39 Correct 75 ms 103104 KB Output is correct
40 Correct 48 ms 103032 KB Output is correct
41 Correct 16 ms 101208 KB Output is correct
42 Correct 19 ms 101212 KB Output is correct
43 Correct 75 ms 102732 KB Output is correct
44 Correct 75 ms 102748 KB Output is correct
45 Correct 85 ms 102940 KB Output is correct
46 Correct 91 ms 102812 KB Output is correct
47 Correct 50 ms 102768 KB Output is correct
48 Correct 56 ms 102652 KB Output is correct
49 Correct 20 ms 101204 KB Output is correct
50 Correct 24 ms 101120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 100956 KB Output is correct
2 Correct 14 ms 101172 KB Output is correct
3 Correct 14 ms 101108 KB Output is correct
4 Correct 14 ms 101192 KB Output is correct
5 Correct 14 ms 100984 KB Output is correct
6 Correct 12 ms 101168 KB Output is correct
7 Correct 13 ms 100956 KB Output is correct
8 Correct 12 ms 101064 KB Output is correct
9 Correct 18 ms 101012 KB Output is correct
10 Correct 16 ms 100984 KB Output is correct
11 Correct 13 ms 100976 KB Output is correct
12 Correct 13 ms 101064 KB Output is correct
13 Correct 14 ms 101096 KB Output is correct
14 Correct 13 ms 100956 KB Output is correct
15 Correct 16 ms 100920 KB Output is correct
16 Correct 13 ms 100836 KB Output is correct
17 Correct 13 ms 101032 KB Output is correct
18 Correct 16 ms 100864 KB Output is correct
19 Correct 22 ms 101096 KB Output is correct
20 Correct 14 ms 100956 KB Output is correct
21 Correct 13 ms 100952 KB Output is correct
22 Correct 12 ms 100956 KB Output is correct
23 Correct 17 ms 100956 KB Output is correct
24 Correct 18 ms 100952 KB Output is correct
25 Correct 60 ms 106868 KB Output is correct
26 Correct 62 ms 106676 KB Output is correct
27 Correct 88 ms 106836 KB Output is correct
28 Correct 97 ms 106744 KB Output is correct
29 Correct 53 ms 106780 KB Output is correct
30 Correct 54 ms 106836 KB Output is correct
31 Correct 18 ms 101720 KB Output is correct
32 Correct 15 ms 101708 KB Output is correct
33 Correct 20 ms 101724 KB Output is correct
34 Correct 17 ms 101768 KB Output is correct
35 Correct 75 ms 103248 KB Output is correct
36 Correct 63 ms 103492 KB Output is correct
37 Correct 85 ms 103260 KB Output is correct
38 Correct 102 ms 103520 KB Output is correct
39 Correct 75 ms 103104 KB Output is correct
40 Correct 48 ms 103032 KB Output is correct
41 Correct 16 ms 101208 KB Output is correct
42 Correct 19 ms 101212 KB Output is correct
43 Correct 75 ms 102732 KB Output is correct
44 Correct 75 ms 102748 KB Output is correct
45 Correct 85 ms 102940 KB Output is correct
46 Correct 91 ms 102812 KB Output is correct
47 Correct 50 ms 102768 KB Output is correct
48 Correct 56 ms 102652 KB Output is correct
49 Correct 20 ms 101204 KB Output is correct
50 Correct 24 ms 101120 KB Output is correct
51 Correct 180 ms 115688 KB Output is correct
52 Correct 156 ms 115788 KB Output is correct
53 Correct 229 ms 115668 KB Output is correct
54 Correct 221 ms 115556 KB Output is correct
55 Correct 113 ms 115556 KB Output is correct
56 Correct 118 ms 115752 KB Output is correct
57 Correct 30 ms 103876 KB Output is correct
58 Correct 27 ms 103768 KB Output is correct
59 Correct 31 ms 103772 KB Output is correct
60 Correct 27 ms 103868 KB Output is correct
61 Correct 149 ms 106832 KB Output is correct
62 Correct 169 ms 107144 KB Output is correct
63 Correct 214 ms 106600 KB Output is correct
64 Correct 194 ms 106832 KB Output is correct
65 Correct 105 ms 106804 KB Output is correct
66 Correct 106 ms 106560 KB Output is correct
67 Correct 31 ms 102032 KB Output is correct
68 Correct 43 ms 101972 KB Output is correct
69 Correct 167 ms 105816 KB Output is correct
70 Correct 175 ms 105804 KB Output is correct
71 Correct 203 ms 105812 KB Output is correct
72 Correct 193 ms 105812 KB Output is correct
73 Correct 103 ms 105568 KB Output is correct
74 Correct 111 ms 105536 KB Output is correct
75 Correct 45 ms 101800 KB Output is correct
76 Correct 35 ms 101720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 100956 KB Output is correct
2 Correct 14 ms 101172 KB Output is correct
3 Correct 14 ms 101108 KB Output is correct
4 Correct 14 ms 101192 KB Output is correct
5 Correct 14 ms 100984 KB Output is correct
6 Correct 12 ms 101168 KB Output is correct
7 Correct 13 ms 100956 KB Output is correct
8 Correct 12 ms 101064 KB Output is correct
9 Correct 18 ms 101012 KB Output is correct
10 Correct 16 ms 100984 KB Output is correct
11 Correct 13 ms 100976 KB Output is correct
12 Correct 13 ms 101064 KB Output is correct
13 Correct 14 ms 101096 KB Output is correct
14 Correct 13 ms 100956 KB Output is correct
15 Correct 16 ms 100920 KB Output is correct
16 Correct 13 ms 100836 KB Output is correct
17 Correct 13 ms 101032 KB Output is correct
18 Correct 16 ms 100864 KB Output is correct
19 Correct 22 ms 101096 KB Output is correct
20 Correct 14 ms 100956 KB Output is correct
21 Correct 13 ms 100952 KB Output is correct
22 Correct 12 ms 100956 KB Output is correct
23 Correct 17 ms 100956 KB Output is correct
24 Correct 18 ms 100952 KB Output is correct
25 Correct 16 ms 101212 KB Output is correct
26 Correct 14 ms 101212 KB Output is correct
27 Correct 18 ms 101212 KB Output is correct
28 Correct 22 ms 101216 KB Output is correct
29 Correct 13 ms 101212 KB Output is correct
30 Correct 14 ms 101100 KB Output is correct
31 Correct 14 ms 101156 KB Output is correct
32 Correct 14 ms 101208 KB Output is correct
33 Correct 14 ms 101212 KB Output is correct
34 Correct 13 ms 101212 KB Output is correct
35 Correct 18 ms 101064 KB Output is correct
36 Correct 18 ms 100956 KB Output is correct
37 Correct 16 ms 101016 KB Output is correct
38 Correct 18 ms 101036 KB Output is correct
39 Correct 14 ms 100956 KB Output is correct
40 Correct 14 ms 101044 KB Output is correct
41 Correct 16 ms 100956 KB Output is correct
42 Correct 22 ms 100956 KB Output is correct
43 Correct 14 ms 100920 KB Output is correct
44 Correct 19 ms 100920 KB Output is correct
45 Correct 17 ms 100956 KB Output is correct
46 Correct 15 ms 101000 KB Output is correct
47 Correct 14 ms 101080 KB Output is correct
48 Correct 13 ms 101116 KB Output is correct
49 Correct 13 ms 100956 KB Output is correct
50 Correct 14 ms 101104 KB Output is correct
51 Correct 60 ms 106868 KB Output is correct
52 Correct 62 ms 106676 KB Output is correct
53 Correct 88 ms 106836 KB Output is correct
54 Correct 97 ms 106744 KB Output is correct
55 Correct 53 ms 106780 KB Output is correct
56 Correct 54 ms 106836 KB Output is correct
57 Correct 18 ms 101720 KB Output is correct
58 Correct 15 ms 101708 KB Output is correct
59 Correct 20 ms 101724 KB Output is correct
60 Correct 17 ms 101768 KB Output is correct
61 Correct 75 ms 103248 KB Output is correct
62 Correct 63 ms 103492 KB Output is correct
63 Correct 85 ms 103260 KB Output is correct
64 Correct 102 ms 103520 KB Output is correct
65 Correct 75 ms 103104 KB Output is correct
66 Correct 48 ms 103032 KB Output is correct
67 Correct 16 ms 101208 KB Output is correct
68 Correct 19 ms 101212 KB Output is correct
69 Correct 75 ms 102732 KB Output is correct
70 Correct 75 ms 102748 KB Output is correct
71 Correct 85 ms 102940 KB Output is correct
72 Correct 91 ms 102812 KB Output is correct
73 Correct 50 ms 102768 KB Output is correct
74 Correct 56 ms 102652 KB Output is correct
75 Correct 20 ms 101204 KB Output is correct
76 Correct 24 ms 101120 KB Output is correct
77 Correct 180 ms 115688 KB Output is correct
78 Correct 156 ms 115788 KB Output is correct
79 Correct 229 ms 115668 KB Output is correct
80 Correct 221 ms 115556 KB Output is correct
81 Correct 113 ms 115556 KB Output is correct
82 Correct 118 ms 115752 KB Output is correct
83 Correct 30 ms 103876 KB Output is correct
84 Correct 27 ms 103768 KB Output is correct
85 Correct 31 ms 103772 KB Output is correct
86 Correct 27 ms 103868 KB Output is correct
87 Correct 149 ms 106832 KB Output is correct
88 Correct 169 ms 107144 KB Output is correct
89 Correct 214 ms 106600 KB Output is correct
90 Correct 194 ms 106832 KB Output is correct
91 Correct 105 ms 106804 KB Output is correct
92 Correct 106 ms 106560 KB Output is correct
93 Correct 31 ms 102032 KB Output is correct
94 Correct 43 ms 101972 KB Output is correct
95 Correct 167 ms 105816 KB Output is correct
96 Correct 175 ms 105804 KB Output is correct
97 Correct 203 ms 105812 KB Output is correct
98 Correct 193 ms 105812 KB Output is correct
99 Correct 103 ms 105568 KB Output is correct
100 Correct 111 ms 105536 KB Output is correct
101 Correct 45 ms 101800 KB Output is correct
102 Correct 35 ms 101720 KB Output is correct
103 Correct 282 ms 118612 KB Output is correct
104 Correct 213 ms 118548 KB Output is correct
105 Correct 492 ms 118996 KB Output is correct
106 Correct 519 ms 119072 KB Output is correct
107 Correct 207 ms 118632 KB Output is correct
108 Correct 223 ms 118792 KB Output is correct
109 Correct 53 ms 104532 KB Output is correct
110 Correct 78 ms 104520 KB Output is correct
111 Correct 52 ms 104532 KB Output is correct
112 Correct 57 ms 104508 KB Output is correct
113 Correct 214 ms 110164 KB Output is correct
114 Correct 291 ms 109908 KB Output is correct
115 Correct 415 ms 110336 KB Output is correct
116 Correct 421 ms 110676 KB Output is correct
117 Correct 209 ms 110008 KB Output is correct
118 Correct 195 ms 109592 KB Output is correct
119 Correct 54 ms 102804 KB Output is correct
120 Correct 53 ms 102856 KB Output is correct
121 Correct 243 ms 108476 KB Output is correct
122 Correct 247 ms 108620 KB Output is correct
123 Correct 410 ms 109396 KB Output is correct
124 Correct 386 ms 109396 KB Output is correct
125 Correct 181 ms 108456 KB Output is correct
126 Correct 175 ms 108544 KB Output is correct
127 Correct 52 ms 102476 KB Output is correct
128 Correct 52 ms 102508 KB Output is correct