답안 #846871

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
846871 2023-09-08T14:55:46 Z Cookie Vinjete (COI22_vinjete) C++14
69 / 100
219 ms 146884 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 = 3e6 + 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 14 ms 42584 KB Output is correct
2 Correct 9 ms 42564 KB Output is correct
3 Correct 9 ms 42488 KB Output is correct
4 Correct 9 ms 42588 KB Output is correct
5 Correct 9 ms 42588 KB Output is correct
6 Correct 9 ms 42584 KB Output is correct
7 Correct 8 ms 42332 KB Output is correct
8 Correct 8 ms 42456 KB Output is correct
9 Correct 9 ms 42588 KB Output is correct
10 Correct 9 ms 42584 KB Output is correct
11 Correct 9 ms 42588 KB Output is correct
12 Correct 9 ms 42588 KB Output is correct
13 Correct 9 ms 42500 KB Output is correct
14 Correct 9 ms 42588 KB Output is correct
15 Correct 8 ms 42332 KB Output is correct
16 Correct 8 ms 42504 KB Output is correct
17 Correct 10 ms 42588 KB Output is correct
18 Correct 9 ms 42588 KB Output is correct
19 Correct 9 ms 42588 KB Output is correct
20 Correct 9 ms 42584 KB Output is correct
21 Correct 9 ms 42488 KB Output is correct
22 Correct 9 ms 42588 KB Output is correct
23 Correct 8 ms 42332 KB Output is correct
24 Correct 8 ms 42328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 42584 KB Output is correct
2 Correct 9 ms 42564 KB Output is correct
3 Correct 9 ms 42488 KB Output is correct
4 Correct 9 ms 42588 KB Output is correct
5 Correct 9 ms 42588 KB Output is correct
6 Correct 9 ms 42584 KB Output is correct
7 Correct 8 ms 42332 KB Output is correct
8 Correct 8 ms 42456 KB Output is correct
9 Correct 9 ms 42588 KB Output is correct
10 Correct 9 ms 42584 KB Output is correct
11 Correct 9 ms 42588 KB Output is correct
12 Correct 9 ms 42588 KB Output is correct
13 Correct 9 ms 42500 KB Output is correct
14 Correct 9 ms 42588 KB Output is correct
15 Correct 8 ms 42332 KB Output is correct
16 Correct 8 ms 42504 KB Output is correct
17 Correct 10 ms 42588 KB Output is correct
18 Correct 9 ms 42588 KB Output is correct
19 Correct 9 ms 42588 KB Output is correct
20 Correct 9 ms 42584 KB Output is correct
21 Correct 9 ms 42488 KB Output is correct
22 Correct 9 ms 42588 KB Output is correct
23 Correct 8 ms 42332 KB Output is correct
24 Correct 8 ms 42328 KB Output is correct
25 Correct 11 ms 42568 KB Output is correct
26 Correct 10 ms 42484 KB Output is correct
27 Correct 11 ms 42868 KB Output is correct
28 Correct 11 ms 42840 KB Output is correct
29 Correct 10 ms 42844 KB Output is correct
30 Correct 9 ms 42844 KB Output is correct
31 Correct 10 ms 42856 KB Output is correct
32 Correct 11 ms 42844 KB Output is correct
33 Correct 11 ms 42824 KB Output is correct
34 Correct 10 ms 42844 KB Output is correct
35 Correct 11 ms 42588 KB Output is correct
36 Correct 10 ms 42588 KB Output is correct
37 Correct 11 ms 42864 KB Output is correct
38 Correct 11 ms 42732 KB Output is correct
39 Correct 9 ms 42588 KB Output is correct
40 Correct 10 ms 42840 KB Output is correct
41 Correct 11 ms 42844 KB Output is correct
42 Correct 10 ms 42844 KB Output is correct
43 Correct 10 ms 42564 KB Output is correct
44 Correct 11 ms 42588 KB Output is correct
45 Correct 11 ms 42864 KB Output is correct
46 Correct 11 ms 42828 KB Output is correct
47 Correct 9 ms 42752 KB Output is correct
48 Correct 10 ms 42588 KB Output is correct
49 Correct 10 ms 42844 KB Output is correct
50 Correct 10 ms 42844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 42584 KB Output is correct
2 Correct 9 ms 42564 KB Output is correct
3 Correct 9 ms 42488 KB Output is correct
4 Correct 9 ms 42588 KB Output is correct
5 Correct 9 ms 42588 KB Output is correct
6 Correct 9 ms 42584 KB Output is correct
7 Correct 8 ms 42332 KB Output is correct
8 Correct 8 ms 42456 KB Output is correct
9 Correct 9 ms 42588 KB Output is correct
10 Correct 9 ms 42584 KB Output is correct
11 Correct 9 ms 42588 KB Output is correct
12 Correct 9 ms 42588 KB Output is correct
13 Correct 9 ms 42500 KB Output is correct
14 Correct 9 ms 42588 KB Output is correct
15 Correct 8 ms 42332 KB Output is correct
16 Correct 8 ms 42504 KB Output is correct
17 Correct 10 ms 42588 KB Output is correct
18 Correct 9 ms 42588 KB Output is correct
19 Correct 9 ms 42588 KB Output is correct
20 Correct 9 ms 42584 KB Output is correct
21 Correct 9 ms 42488 KB Output is correct
22 Correct 9 ms 42588 KB Output is correct
23 Correct 8 ms 42332 KB Output is correct
24 Correct 8 ms 42328 KB Output is correct
25 Correct 56 ms 47820 KB Output is correct
26 Correct 54 ms 47956 KB Output is correct
27 Correct 65 ms 48400 KB Output is correct
28 Correct 61 ms 48208 KB Output is correct
29 Correct 43 ms 48208 KB Output is correct
30 Correct 49 ms 48220 KB Output is correct
31 Correct 12 ms 43356 KB Output is correct
32 Correct 13 ms 43356 KB Output is correct
33 Correct 12 ms 43356 KB Output is correct
34 Correct 13 ms 43356 KB Output is correct
35 Correct 57 ms 45056 KB Output is correct
36 Correct 54 ms 45208 KB Output is correct
37 Correct 62 ms 45512 KB Output is correct
38 Correct 61 ms 45908 KB Output is correct
39 Correct 42 ms 45648 KB Output is correct
40 Correct 43 ms 45392 KB Output is correct
41 Correct 12 ms 42844 KB Output is correct
42 Correct 12 ms 42844 KB Output is correct
43 Correct 54 ms 45068 KB Output is correct
44 Correct 55 ms 44884 KB Output is correct
45 Correct 68 ms 45412 KB Output is correct
46 Correct 63 ms 45252 KB Output is correct
47 Correct 41 ms 45136 KB Output is correct
48 Correct 41 ms 45148 KB Output is correct
49 Correct 12 ms 42840 KB Output is correct
50 Correct 12 ms 42952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 42584 KB Output is correct
2 Correct 9 ms 42564 KB Output is correct
3 Correct 9 ms 42488 KB Output is correct
4 Correct 9 ms 42588 KB Output is correct
5 Correct 9 ms 42588 KB Output is correct
6 Correct 9 ms 42584 KB Output is correct
7 Correct 8 ms 42332 KB Output is correct
8 Correct 8 ms 42456 KB Output is correct
9 Correct 9 ms 42588 KB Output is correct
10 Correct 9 ms 42584 KB Output is correct
11 Correct 9 ms 42588 KB Output is correct
12 Correct 9 ms 42588 KB Output is correct
13 Correct 9 ms 42500 KB Output is correct
14 Correct 9 ms 42588 KB Output is correct
15 Correct 8 ms 42332 KB Output is correct
16 Correct 8 ms 42504 KB Output is correct
17 Correct 10 ms 42588 KB Output is correct
18 Correct 9 ms 42588 KB Output is correct
19 Correct 9 ms 42588 KB Output is correct
20 Correct 9 ms 42584 KB Output is correct
21 Correct 9 ms 42488 KB Output is correct
22 Correct 9 ms 42588 KB Output is correct
23 Correct 8 ms 42332 KB Output is correct
24 Correct 8 ms 42328 KB Output is correct
25 Correct 56 ms 47820 KB Output is correct
26 Correct 54 ms 47956 KB Output is correct
27 Correct 65 ms 48400 KB Output is correct
28 Correct 61 ms 48208 KB Output is correct
29 Correct 43 ms 48208 KB Output is correct
30 Correct 49 ms 48220 KB Output is correct
31 Correct 12 ms 43356 KB Output is correct
32 Correct 13 ms 43356 KB Output is correct
33 Correct 12 ms 43356 KB Output is correct
34 Correct 13 ms 43356 KB Output is correct
35 Correct 57 ms 45056 KB Output is correct
36 Correct 54 ms 45208 KB Output is correct
37 Correct 62 ms 45512 KB Output is correct
38 Correct 61 ms 45908 KB Output is correct
39 Correct 42 ms 45648 KB Output is correct
40 Correct 43 ms 45392 KB Output is correct
41 Correct 12 ms 42844 KB Output is correct
42 Correct 12 ms 42844 KB Output is correct
43 Correct 54 ms 45068 KB Output is correct
44 Correct 55 ms 44884 KB Output is correct
45 Correct 68 ms 45412 KB Output is correct
46 Correct 63 ms 45252 KB Output is correct
47 Correct 41 ms 45136 KB Output is correct
48 Correct 41 ms 45148 KB Output is correct
49 Correct 12 ms 42840 KB Output is correct
50 Correct 12 ms 42952 KB Output is correct
51 Correct 128 ms 56148 KB Output is correct
52 Correct 132 ms 56040 KB Output is correct
53 Correct 156 ms 57168 KB Output is correct
54 Correct 156 ms 57200 KB Output is correct
55 Correct 100 ms 56916 KB Output is correct
56 Correct 106 ms 56956 KB Output is correct
57 Correct 24 ms 45652 KB Output is correct
58 Correct 25 ms 45656 KB Output is correct
59 Correct 24 ms 45660 KB Output is correct
60 Correct 25 ms 45648 KB Output is correct
61 Correct 129 ms 49616 KB Output is correct
62 Correct 128 ms 49856 KB Output is correct
63 Correct 157 ms 50412 KB Output is correct
64 Correct 181 ms 50600 KB Output is correct
65 Correct 115 ms 50564 KB Output is correct
66 Correct 117 ms 50372 KB Output is correct
67 Correct 28 ms 44336 KB Output is correct
68 Correct 29 ms 44340 KB Output is correct
69 Correct 137 ms 48724 KB Output is correct
70 Correct 148 ms 49084 KB Output is correct
71 Correct 180 ms 49732 KB Output is correct
72 Correct 159 ms 49776 KB Output is correct
73 Correct 121 ms 49520 KB Output is correct
74 Correct 98 ms 49492 KB Output is correct
75 Correct 29 ms 44120 KB Output is correct
76 Correct 27 ms 44144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 42584 KB Output is correct
2 Correct 9 ms 42564 KB Output is correct
3 Correct 9 ms 42488 KB Output is correct
4 Correct 9 ms 42588 KB Output is correct
5 Correct 9 ms 42588 KB Output is correct
6 Correct 9 ms 42584 KB Output is correct
7 Correct 8 ms 42332 KB Output is correct
8 Correct 8 ms 42456 KB Output is correct
9 Correct 9 ms 42588 KB Output is correct
10 Correct 9 ms 42584 KB Output is correct
11 Correct 9 ms 42588 KB Output is correct
12 Correct 9 ms 42588 KB Output is correct
13 Correct 9 ms 42500 KB Output is correct
14 Correct 9 ms 42588 KB Output is correct
15 Correct 8 ms 42332 KB Output is correct
16 Correct 8 ms 42504 KB Output is correct
17 Correct 10 ms 42588 KB Output is correct
18 Correct 9 ms 42588 KB Output is correct
19 Correct 9 ms 42588 KB Output is correct
20 Correct 9 ms 42584 KB Output is correct
21 Correct 9 ms 42488 KB Output is correct
22 Correct 9 ms 42588 KB Output is correct
23 Correct 8 ms 42332 KB Output is correct
24 Correct 8 ms 42328 KB Output is correct
25 Correct 11 ms 42568 KB Output is correct
26 Correct 10 ms 42484 KB Output is correct
27 Correct 11 ms 42868 KB Output is correct
28 Correct 11 ms 42840 KB Output is correct
29 Correct 10 ms 42844 KB Output is correct
30 Correct 9 ms 42844 KB Output is correct
31 Correct 10 ms 42856 KB Output is correct
32 Correct 11 ms 42844 KB Output is correct
33 Correct 11 ms 42824 KB Output is correct
34 Correct 10 ms 42844 KB Output is correct
35 Correct 11 ms 42588 KB Output is correct
36 Correct 10 ms 42588 KB Output is correct
37 Correct 11 ms 42864 KB Output is correct
38 Correct 11 ms 42732 KB Output is correct
39 Correct 9 ms 42588 KB Output is correct
40 Correct 10 ms 42840 KB Output is correct
41 Correct 11 ms 42844 KB Output is correct
42 Correct 10 ms 42844 KB Output is correct
43 Correct 10 ms 42564 KB Output is correct
44 Correct 11 ms 42588 KB Output is correct
45 Correct 11 ms 42864 KB Output is correct
46 Correct 11 ms 42828 KB Output is correct
47 Correct 9 ms 42752 KB Output is correct
48 Correct 10 ms 42588 KB Output is correct
49 Correct 10 ms 42844 KB Output is correct
50 Correct 10 ms 42844 KB Output is correct
51 Correct 56 ms 47820 KB Output is correct
52 Correct 54 ms 47956 KB Output is correct
53 Correct 65 ms 48400 KB Output is correct
54 Correct 61 ms 48208 KB Output is correct
55 Correct 43 ms 48208 KB Output is correct
56 Correct 49 ms 48220 KB Output is correct
57 Correct 12 ms 43356 KB Output is correct
58 Correct 13 ms 43356 KB Output is correct
59 Correct 12 ms 43356 KB Output is correct
60 Correct 13 ms 43356 KB Output is correct
61 Correct 57 ms 45056 KB Output is correct
62 Correct 54 ms 45208 KB Output is correct
63 Correct 62 ms 45512 KB Output is correct
64 Correct 61 ms 45908 KB Output is correct
65 Correct 42 ms 45648 KB Output is correct
66 Correct 43 ms 45392 KB Output is correct
67 Correct 12 ms 42844 KB Output is correct
68 Correct 12 ms 42844 KB Output is correct
69 Correct 54 ms 45068 KB Output is correct
70 Correct 55 ms 44884 KB Output is correct
71 Correct 68 ms 45412 KB Output is correct
72 Correct 63 ms 45252 KB Output is correct
73 Correct 41 ms 45136 KB Output is correct
74 Correct 41 ms 45148 KB Output is correct
75 Correct 12 ms 42840 KB Output is correct
76 Correct 12 ms 42952 KB Output is correct
77 Correct 128 ms 56148 KB Output is correct
78 Correct 132 ms 56040 KB Output is correct
79 Correct 156 ms 57168 KB Output is correct
80 Correct 156 ms 57200 KB Output is correct
81 Correct 100 ms 56916 KB Output is correct
82 Correct 106 ms 56956 KB Output is correct
83 Correct 24 ms 45652 KB Output is correct
84 Correct 25 ms 45656 KB Output is correct
85 Correct 24 ms 45660 KB Output is correct
86 Correct 25 ms 45648 KB Output is correct
87 Correct 129 ms 49616 KB Output is correct
88 Correct 128 ms 49856 KB Output is correct
89 Correct 157 ms 50412 KB Output is correct
90 Correct 181 ms 50600 KB Output is correct
91 Correct 115 ms 50564 KB Output is correct
92 Correct 117 ms 50372 KB Output is correct
93 Correct 28 ms 44336 KB Output is correct
94 Correct 29 ms 44340 KB Output is correct
95 Correct 137 ms 48724 KB Output is correct
96 Correct 148 ms 49084 KB Output is correct
97 Correct 180 ms 49732 KB Output is correct
98 Correct 159 ms 49776 KB Output is correct
99 Correct 121 ms 49520 KB Output is correct
100 Correct 98 ms 49492 KB Output is correct
101 Correct 29 ms 44120 KB Output is correct
102 Correct 27 ms 44144 KB Output is correct
103 Correct 207 ms 56944 KB Output is correct
104 Correct 215 ms 56860 KB Output is correct
105 Runtime error 219 ms 146884 KB Execution killed with signal 6
106 Halted 0 ms 0 KB -