답안 #846872

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
846872 2023-09-08T14:56:22 Z Cookie Vinjete (COI22_vinjete) C++14
100 / 100
422 ms 150416 KB
#include<bits/stdc++.h>
#define ll long long
#define vt vector
#define pb push_back
#define pii pair<int, int>
#define sz(v) (int)v.size()
#define fi first
#define se second
using namespace std;
const ll base = 107, mod = 1e9 + 7;
const int mxn = 1e5 + 5, N = 8e6 + 5;
struct Node{
    int mn = 0, cnt = 0, lz = 0;
    Node(){
        mn = cnt = lz = 0;
    }
    Node(int _mn, int _cnt, int _lz){
        mn = _mn; cnt = _cnt; lz = _lz;
    }
};
int n, m;
vt<pii>adj[mxn + 1];
int lp[mxn + 1], rp[mxn + 1], id = 1, ans[mxn + 1], toedge[mxn + 1];
int lson[N], rson[N];
Node st[N];
void push(int nd, int l, int mid, int r){
    int &v = st[nd].lz;
    if(!lson[nd]){
        //cout << nd << " ";
        lson[nd] = ++id; st[id].cnt = mid - l + 1; 
        rson[nd] = ++id; st[id].cnt = r - mid;
    }
    //cout << l << " " << r << " " << v << "\n";
    st[lson[nd]].lz += v; st[lson[nd]].mn += v;
    st[rson[nd]].lz += v; st[rson[nd]].mn += v;
    v = 0;
    st[nd].lz = 0;
    assert(st[nd].lz == 0);
}
Node comb(Node a, Node b){
    if(a.mn < b.mn){
        Node res; res.mn = a.mn; res.cnt = a.cnt;
        return(res);
    }
    if(a.mn > b.mn){
        Node res; res.mn = b.mn; res.cnt = b.cnt;
        return(res);
    }
    Node res; res.mn = a.mn;
    res.cnt = a.cnt + b.cnt; res.lz = 0;
    return(res);
}
void upd(int nd, int l, int r, int ql, int qr, int v){
    if(ql > r || qr < l)return;
    if(ql <= l && qr >= r){
        st[nd].mn += v; st[nd].lz += v;
        
        return;
    }
    
    int mid = (l + r) >> 1;
    push(nd, l, mid, r);
    
    upd(lson[nd], l, mid, ql, qr, v); upd(rson[nd], mid + 1, r, ql, qr, v);
    assert(st[nd].lz == 0);
    st[nd] = comb(st[lson[nd]], st[rson[nd]]);
    assert(st[nd].lz == 0);
}
void dfs(int s, int pre){
    
    //cout << s << " " <<  st[1].mn << "\n";
    if(st[1].mn != 0)ans[s] = 0;
    else ans[s] = st[1].cnt;
    for(int i = 0; i < sz(adj[s]); i++){
        int v = adj[s][i].first, id = adj[s][i].second;
        if(v == pre)continue;
        toedge[v] = id;
        upd(1, 1, m, lp[id], rp[id], 1);
        
        
        dfs(v, s);
        upd(1, 1, m, lp[id], rp[id], -1);
        
    }
    //cout << s << " " <<  st[1].mn << "\n";
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    st[1].cnt = m;
    for(int i = 1; i < n; i++){
        int u, v; cin >> u >> v >> lp[i] >> rp[i];
        adj[u].pb({v, i}); adj[v].pb({u, i});
        
    }
    dfs(1, -1);
    for(int i = 2; i <= n; i++){
      assert(ans[i] <= m);
      cout << m - ans[i] << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 99412 KB Output is correct
2 Correct 18 ms 99420 KB Output is correct
3 Correct 19 ms 99256 KB Output is correct
4 Correct 19 ms 99420 KB Output is correct
5 Correct 18 ms 99672 KB Output is correct
6 Correct 18 ms 99420 KB Output is correct
7 Correct 18 ms 99144 KB Output is correct
8 Correct 18 ms 99164 KB Output is correct
9 Correct 19 ms 99316 KB Output is correct
10 Correct 19 ms 99416 KB Output is correct
11 Correct 19 ms 99152 KB Output is correct
12 Correct 19 ms 99408 KB Output is correct
13 Correct 19 ms 99420 KB Output is correct
14 Correct 18 ms 99304 KB Output is correct
15 Correct 20 ms 99420 KB Output is correct
16 Correct 18 ms 99160 KB Output is correct
17 Correct 18 ms 99420 KB Output is correct
18 Correct 18 ms 99164 KB Output is correct
19 Correct 19 ms 99420 KB Output is correct
20 Correct 19 ms 99416 KB Output is correct
21 Correct 19 ms 99420 KB Output is correct
22 Correct 19 ms 99164 KB Output is correct
23 Correct 19 ms 99228 KB Output is correct
24 Correct 18 ms 99160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 99412 KB Output is correct
2 Correct 18 ms 99420 KB Output is correct
3 Correct 19 ms 99256 KB Output is correct
4 Correct 19 ms 99420 KB Output is correct
5 Correct 18 ms 99672 KB Output is correct
6 Correct 18 ms 99420 KB Output is correct
7 Correct 18 ms 99144 KB Output is correct
8 Correct 18 ms 99164 KB Output is correct
9 Correct 19 ms 99316 KB Output is correct
10 Correct 19 ms 99416 KB Output is correct
11 Correct 19 ms 99152 KB Output is correct
12 Correct 19 ms 99408 KB Output is correct
13 Correct 19 ms 99420 KB Output is correct
14 Correct 18 ms 99304 KB Output is correct
15 Correct 20 ms 99420 KB Output is correct
16 Correct 18 ms 99160 KB Output is correct
17 Correct 18 ms 99420 KB Output is correct
18 Correct 18 ms 99164 KB Output is correct
19 Correct 19 ms 99420 KB Output is correct
20 Correct 19 ms 99416 KB Output is correct
21 Correct 19 ms 99420 KB Output is correct
22 Correct 19 ms 99164 KB Output is correct
23 Correct 19 ms 99228 KB Output is correct
24 Correct 18 ms 99160 KB Output is correct
25 Correct 22 ms 99420 KB Output is correct
26 Correct 21 ms 99436 KB Output is correct
27 Correct 20 ms 99672 KB Output is correct
28 Correct 20 ms 99724 KB Output is correct
29 Correct 19 ms 99420 KB Output is correct
30 Correct 20 ms 99508 KB Output is correct
31 Correct 20 ms 99672 KB Output is correct
32 Correct 19 ms 99580 KB Output is correct
33 Correct 20 ms 99676 KB Output is correct
34 Correct 20 ms 99676 KB Output is correct
35 Correct 21 ms 99212 KB Output is correct
36 Correct 21 ms 99408 KB Output is correct
37 Correct 21 ms 99640 KB Output is correct
38 Correct 21 ms 99676 KB Output is correct
39 Correct 20 ms 99420 KB Output is correct
40 Correct 20 ms 99400 KB Output is correct
41 Correct 20 ms 99676 KB Output is correct
42 Correct 21 ms 99440 KB Output is correct
43 Correct 21 ms 99240 KB Output is correct
44 Correct 21 ms 99416 KB Output is correct
45 Correct 21 ms 99500 KB Output is correct
46 Correct 20 ms 99676 KB Output is correct
47 Correct 19 ms 99564 KB Output is correct
48 Correct 22 ms 99420 KB Output is correct
49 Correct 20 ms 99672 KB Output is correct
50 Correct 20 ms 99812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 99412 KB Output is correct
2 Correct 18 ms 99420 KB Output is correct
3 Correct 19 ms 99256 KB Output is correct
4 Correct 19 ms 99420 KB Output is correct
5 Correct 18 ms 99672 KB Output is correct
6 Correct 18 ms 99420 KB Output is correct
7 Correct 18 ms 99144 KB Output is correct
8 Correct 18 ms 99164 KB Output is correct
9 Correct 19 ms 99316 KB Output is correct
10 Correct 19 ms 99416 KB Output is correct
11 Correct 19 ms 99152 KB Output is correct
12 Correct 19 ms 99408 KB Output is correct
13 Correct 19 ms 99420 KB Output is correct
14 Correct 18 ms 99304 KB Output is correct
15 Correct 20 ms 99420 KB Output is correct
16 Correct 18 ms 99160 KB Output is correct
17 Correct 18 ms 99420 KB Output is correct
18 Correct 18 ms 99164 KB Output is correct
19 Correct 19 ms 99420 KB Output is correct
20 Correct 19 ms 99416 KB Output is correct
21 Correct 19 ms 99420 KB Output is correct
22 Correct 19 ms 99164 KB Output is correct
23 Correct 19 ms 99228 KB Output is correct
24 Correct 18 ms 99160 KB Output is correct
25 Correct 63 ms 103760 KB Output is correct
26 Correct 63 ms 103740 KB Output is correct
27 Correct 84 ms 104112 KB Output is correct
28 Correct 72 ms 104020 KB Output is correct
29 Correct 58 ms 104120 KB Output is correct
30 Correct 53 ms 104160 KB Output is correct
31 Correct 23 ms 99924 KB Output is correct
32 Correct 22 ms 99932 KB Output is correct
33 Correct 22 ms 99924 KB Output is correct
34 Correct 26 ms 99932 KB Output is correct
35 Correct 69 ms 101284 KB Output is correct
36 Correct 66 ms 101460 KB Output is correct
37 Correct 79 ms 101356 KB Output is correct
38 Correct 74 ms 101560 KB Output is correct
39 Correct 53 ms 101456 KB Output is correct
40 Correct 54 ms 101528 KB Output is correct
41 Correct 23 ms 99668 KB Output is correct
42 Correct 23 ms 99676 KB Output is correct
43 Correct 68 ms 100852 KB Output is correct
44 Correct 69 ms 100948 KB Output is correct
45 Correct 84 ms 101344 KB Output is correct
46 Correct 74 ms 101204 KB Output is correct
47 Correct 56 ms 101204 KB Output is correct
48 Correct 56 ms 101224 KB Output is correct
49 Correct 22 ms 99664 KB Output is correct
50 Correct 22 ms 99528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 99412 KB Output is correct
2 Correct 18 ms 99420 KB Output is correct
3 Correct 19 ms 99256 KB Output is correct
4 Correct 19 ms 99420 KB Output is correct
5 Correct 18 ms 99672 KB Output is correct
6 Correct 18 ms 99420 KB Output is correct
7 Correct 18 ms 99144 KB Output is correct
8 Correct 18 ms 99164 KB Output is correct
9 Correct 19 ms 99316 KB Output is correct
10 Correct 19 ms 99416 KB Output is correct
11 Correct 19 ms 99152 KB Output is correct
12 Correct 19 ms 99408 KB Output is correct
13 Correct 19 ms 99420 KB Output is correct
14 Correct 18 ms 99304 KB Output is correct
15 Correct 20 ms 99420 KB Output is correct
16 Correct 18 ms 99160 KB Output is correct
17 Correct 18 ms 99420 KB Output is correct
18 Correct 18 ms 99164 KB Output is correct
19 Correct 19 ms 99420 KB Output is correct
20 Correct 19 ms 99416 KB Output is correct
21 Correct 19 ms 99420 KB Output is correct
22 Correct 19 ms 99164 KB Output is correct
23 Correct 19 ms 99228 KB Output is correct
24 Correct 18 ms 99160 KB Output is correct
25 Correct 63 ms 103760 KB Output is correct
26 Correct 63 ms 103740 KB Output is correct
27 Correct 84 ms 104112 KB Output is correct
28 Correct 72 ms 104020 KB Output is correct
29 Correct 58 ms 104120 KB Output is correct
30 Correct 53 ms 104160 KB Output is correct
31 Correct 23 ms 99924 KB Output is correct
32 Correct 22 ms 99932 KB Output is correct
33 Correct 22 ms 99924 KB Output is correct
34 Correct 26 ms 99932 KB Output is correct
35 Correct 69 ms 101284 KB Output is correct
36 Correct 66 ms 101460 KB Output is correct
37 Correct 79 ms 101356 KB Output is correct
38 Correct 74 ms 101560 KB Output is correct
39 Correct 53 ms 101456 KB Output is correct
40 Correct 54 ms 101528 KB Output is correct
41 Correct 23 ms 99668 KB Output is correct
42 Correct 23 ms 99676 KB Output is correct
43 Correct 68 ms 100852 KB Output is correct
44 Correct 69 ms 100948 KB Output is correct
45 Correct 84 ms 101344 KB Output is correct
46 Correct 74 ms 101204 KB Output is correct
47 Correct 56 ms 101204 KB Output is correct
48 Correct 56 ms 101224 KB Output is correct
49 Correct 22 ms 99664 KB Output is correct
50 Correct 22 ms 99528 KB Output is correct
51 Correct 142 ms 110868 KB Output is correct
52 Correct 137 ms 110812 KB Output is correct
53 Correct 170 ms 113748 KB Output is correct
54 Correct 166 ms 113744 KB Output is correct
55 Correct 109 ms 113592 KB Output is correct
56 Correct 117 ms 113492 KB Output is correct
57 Correct 36 ms 102032 KB Output is correct
58 Correct 37 ms 101972 KB Output is correct
59 Correct 35 ms 102056 KB Output is correct
60 Correct 36 ms 102032 KB Output is correct
61 Correct 150 ms 104560 KB Output is correct
62 Correct 154 ms 104532 KB Output is correct
63 Correct 180 ms 107088 KB Output is correct
64 Correct 181 ms 106992 KB Output is correct
65 Correct 125 ms 107228 KB Output is correct
66 Correct 122 ms 107088 KB Output is correct
67 Correct 43 ms 100656 KB Output is correct
68 Correct 36 ms 100692 KB Output is correct
69 Correct 154 ms 103604 KB Output is correct
70 Correct 162 ms 103504 KB Output is correct
71 Correct 205 ms 106232 KB Output is correct
72 Correct 173 ms 106320 KB Output is correct
73 Correct 137 ms 106132 KB Output is correct
74 Correct 120 ms 106136 KB Output is correct
75 Correct 42 ms 100588 KB Output is correct
76 Correct 41 ms 100548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 99412 KB Output is correct
2 Correct 18 ms 99420 KB Output is correct
3 Correct 19 ms 99256 KB Output is correct
4 Correct 19 ms 99420 KB Output is correct
5 Correct 18 ms 99672 KB Output is correct
6 Correct 18 ms 99420 KB Output is correct
7 Correct 18 ms 99144 KB Output is correct
8 Correct 18 ms 99164 KB Output is correct
9 Correct 19 ms 99316 KB Output is correct
10 Correct 19 ms 99416 KB Output is correct
11 Correct 19 ms 99152 KB Output is correct
12 Correct 19 ms 99408 KB Output is correct
13 Correct 19 ms 99420 KB Output is correct
14 Correct 18 ms 99304 KB Output is correct
15 Correct 20 ms 99420 KB Output is correct
16 Correct 18 ms 99160 KB Output is correct
17 Correct 18 ms 99420 KB Output is correct
18 Correct 18 ms 99164 KB Output is correct
19 Correct 19 ms 99420 KB Output is correct
20 Correct 19 ms 99416 KB Output is correct
21 Correct 19 ms 99420 KB Output is correct
22 Correct 19 ms 99164 KB Output is correct
23 Correct 19 ms 99228 KB Output is correct
24 Correct 18 ms 99160 KB Output is correct
25 Correct 22 ms 99420 KB Output is correct
26 Correct 21 ms 99436 KB Output is correct
27 Correct 20 ms 99672 KB Output is correct
28 Correct 20 ms 99724 KB Output is correct
29 Correct 19 ms 99420 KB Output is correct
30 Correct 20 ms 99508 KB Output is correct
31 Correct 20 ms 99672 KB Output is correct
32 Correct 19 ms 99580 KB Output is correct
33 Correct 20 ms 99676 KB Output is correct
34 Correct 20 ms 99676 KB Output is correct
35 Correct 21 ms 99212 KB Output is correct
36 Correct 21 ms 99408 KB Output is correct
37 Correct 21 ms 99640 KB Output is correct
38 Correct 21 ms 99676 KB Output is correct
39 Correct 20 ms 99420 KB Output is correct
40 Correct 20 ms 99400 KB Output is correct
41 Correct 20 ms 99676 KB Output is correct
42 Correct 21 ms 99440 KB Output is correct
43 Correct 21 ms 99240 KB Output is correct
44 Correct 21 ms 99416 KB Output is correct
45 Correct 21 ms 99500 KB Output is correct
46 Correct 20 ms 99676 KB Output is correct
47 Correct 19 ms 99564 KB Output is correct
48 Correct 22 ms 99420 KB Output is correct
49 Correct 20 ms 99672 KB Output is correct
50 Correct 20 ms 99812 KB Output is correct
51 Correct 63 ms 103760 KB Output is correct
52 Correct 63 ms 103740 KB Output is correct
53 Correct 84 ms 104112 KB Output is correct
54 Correct 72 ms 104020 KB Output is correct
55 Correct 58 ms 104120 KB Output is correct
56 Correct 53 ms 104160 KB Output is correct
57 Correct 23 ms 99924 KB Output is correct
58 Correct 22 ms 99932 KB Output is correct
59 Correct 22 ms 99924 KB Output is correct
60 Correct 26 ms 99932 KB Output is correct
61 Correct 69 ms 101284 KB Output is correct
62 Correct 66 ms 101460 KB Output is correct
63 Correct 79 ms 101356 KB Output is correct
64 Correct 74 ms 101560 KB Output is correct
65 Correct 53 ms 101456 KB Output is correct
66 Correct 54 ms 101528 KB Output is correct
67 Correct 23 ms 99668 KB Output is correct
68 Correct 23 ms 99676 KB Output is correct
69 Correct 68 ms 100852 KB Output is correct
70 Correct 69 ms 100948 KB Output is correct
71 Correct 84 ms 101344 KB Output is correct
72 Correct 74 ms 101204 KB Output is correct
73 Correct 56 ms 101204 KB Output is correct
74 Correct 56 ms 101224 KB Output is correct
75 Correct 22 ms 99664 KB Output is correct
76 Correct 22 ms 99528 KB Output is correct
77 Correct 142 ms 110868 KB Output is correct
78 Correct 137 ms 110812 KB Output is correct
79 Correct 170 ms 113748 KB Output is correct
80 Correct 166 ms 113744 KB Output is correct
81 Correct 109 ms 113592 KB Output is correct
82 Correct 117 ms 113492 KB Output is correct
83 Correct 36 ms 102032 KB Output is correct
84 Correct 37 ms 101972 KB Output is correct
85 Correct 35 ms 102056 KB Output is correct
86 Correct 36 ms 102032 KB Output is correct
87 Correct 150 ms 104560 KB Output is correct
88 Correct 154 ms 104532 KB Output is correct
89 Correct 180 ms 107088 KB Output is correct
90 Correct 181 ms 106992 KB Output is correct
91 Correct 125 ms 107228 KB Output is correct
92 Correct 122 ms 107088 KB Output is correct
93 Correct 43 ms 100656 KB Output is correct
94 Correct 36 ms 100692 KB Output is correct
95 Correct 154 ms 103604 KB Output is correct
96 Correct 162 ms 103504 KB Output is correct
97 Correct 205 ms 106232 KB Output is correct
98 Correct 173 ms 106320 KB Output is correct
99 Correct 137 ms 106132 KB Output is correct
100 Correct 120 ms 106136 KB Output is correct
101 Correct 42 ms 100588 KB Output is correct
102 Correct 41 ms 100548 KB Output is correct
103 Correct 210 ms 111348 KB Output is correct
104 Correct 208 ms 111360 KB Output is correct
105 Correct 422 ms 147200 KB Output is correct
106 Correct 403 ms 150416 KB Output is correct
107 Correct 220 ms 134684 KB Output is correct
108 Correct 213 ms 134568 KB Output is correct
109 Correct 59 ms 110752 KB Output is correct
110 Correct 57 ms 110552 KB Output is correct
111 Correct 65 ms 110856 KB Output is correct
112 Correct 63 ms 110628 KB Output is correct
113 Correct 226 ms 107612 KB Output is correct
114 Correct 235 ms 107384 KB Output is correct
115 Correct 377 ms 143936 KB Output is correct
116 Correct 398 ms 144140 KB Output is correct
117 Correct 209 ms 128136 KB Output is correct
118 Correct 215 ms 127824 KB Output is correct
119 Correct 62 ms 109336 KB Output is correct
120 Correct 59 ms 109244 KB Output is correct
121 Correct 238 ms 106288 KB Output is correct
122 Correct 278 ms 106284 KB Output is correct
123 Correct 382 ms 143300 KB Output is correct
124 Correct 386 ms 143268 KB Output is correct
125 Correct 243 ms 127160 KB Output is correct
126 Correct 207 ms 127180 KB Output is correct
127 Correct 67 ms 109152 KB Output is correct
128 Correct 60 ms 109136 KB Output is correct