Submission #953545

# Submission time Handle Problem Language Result Execution time Memory
953545 2024-03-26T06:40:56 Z tnknguyen_ Vinjete (COI22_vinjete) C++14
100 / 100
519 ms 193292 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n' 
#define pii pair<int, int>
 
const int MX = 1e5 + 5;
vector<pair<int, pii>> gr[MX];
int L[MX], R[MX], f[MX];
int ans[MX];
 
struct node{
    int good, sum;
    node *l, *r;

    node(){
        this->good = this->sum = 0;
        this->l = this->r = NULL;
    }
};
 
struct SMT{ 
    // vector<node> tree;
    node *root;
    int n;
 
    SMT(){
        // tree.assign(4*n + 5, node());
        this->n = 1e9 + 5;
        this->root = new node();
    };
 
    node *update(node *cur, int l, int r, int u, int v, int val){
        if(r < u || l > v){
            return cur;
        }
        if(cur == NULL){
            cur = new node();
        }
        if(u <= l && r <= v){
            cur->good += val;
            cur->sum = (cur->good ? r-l+1 : (cur->l ? cur->l->sum : 0) + (cur->r ? cur->r->sum : 0));
            // tree[id].good += val;
            // tree[id].sum = (tree[id].good ? r-l+1 : tree[2*id].sum + tree[2*id+1].sum);
            return cur;
        }
        int mid = (l + r) >> 1;
        cur->l = update(cur->l, l, mid, u, v, val);
        cur->r = update(cur->r, mid+1, r, u, v, val);
 
        // tree[id].sum = (tree[id].good ? r-l+1 : tree[ID].sum + tree[ID|1].sum);
        cur->sum = (cur->good ? r-l+1 : (cur->l ? cur->l->sum : 0) + (cur->r ? cur->r->sum : 0));
        return cur;
    }
 
    void update(int l, int r, int val){
        root = update(root, 1, n, l, r, val);
    }
 
    int get(node *cur, int l, int r, int u, int v){
        if(r < u || l > v || cur == NULL){
            return 0;
        }
        if(u <= l && r <= v){
            return cur->sum;
        }
        int mid = (l + r) >> 1;
        return get(cur->l, l, mid, u, v) + get(cur->r, mid+1, r, u, v);
    }
};
SMT smt;
 
void dfs(int u, int p){
    ans[u] = smt.root->sum;
    for(pair<int, pii> e : gr[u]){
        int v, l, r;
        v = e.first;
        tie(l, r) = e.second;
        if(v != p){
            smt.update(l, r, 1);
            dfs(v, u);
            smt.update(l, r, -1);
        }
    }
}
 
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
//    freopen("main.inp","r",stdin);
//    freopen("main.out","w",stdout);
 
    int n, m;
    cin>>n>>m;
 
    for(int i=1; i<n; ++i){
        int u, v, l, r;
        cin>>u>>v>>l>>r;
        gr[u].push_back({v, {l, r}});
        gr[v].push_back({u, {l, r}});
    }
 
    dfs(1, 0);
 
    for(int i=2; i<=n; ++i){
        cout<<ans[i]<<endl;
    }
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3932 KB Output is correct
2 Correct 2 ms 3932 KB Output is correct
3 Correct 2 ms 3932 KB Output is correct
4 Correct 3 ms 3932 KB Output is correct
5 Correct 2 ms 3932 KB Output is correct
6 Correct 2 ms 4044 KB Output is correct
7 Correct 1 ms 3672 KB Output is correct
8 Correct 1 ms 3676 KB Output is correct
9 Correct 3 ms 3676 KB Output is correct
10 Correct 2 ms 3672 KB Output is correct
11 Correct 2 ms 3676 KB Output is correct
12 Correct 2 ms 3676 KB Output is correct
13 Correct 2 ms 3676 KB Output is correct
14 Correct 2 ms 3676 KB Output is correct
15 Correct 1 ms 3676 KB Output is correct
16 Correct 1 ms 3676 KB Output is correct
17 Correct 2 ms 3672 KB Output is correct
18 Correct 2 ms 3676 KB Output is correct
19 Correct 2 ms 3676 KB Output is correct
20 Correct 2 ms 3676 KB Output is correct
21 Correct 2 ms 3676 KB Output is correct
22 Correct 2 ms 3676 KB Output is correct
23 Correct 1 ms 3676 KB Output is correct
24 Correct 2 ms 3676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3932 KB Output is correct
2 Correct 2 ms 3932 KB Output is correct
3 Correct 2 ms 3932 KB Output is correct
4 Correct 3 ms 3932 KB Output is correct
5 Correct 2 ms 3932 KB Output is correct
6 Correct 2 ms 4044 KB Output is correct
7 Correct 1 ms 3672 KB Output is correct
8 Correct 1 ms 3676 KB Output is correct
9 Correct 3 ms 3676 KB Output is correct
10 Correct 2 ms 3672 KB Output is correct
11 Correct 2 ms 3676 KB Output is correct
12 Correct 2 ms 3676 KB Output is correct
13 Correct 2 ms 3676 KB Output is correct
14 Correct 2 ms 3676 KB Output is correct
15 Correct 1 ms 3676 KB Output is correct
16 Correct 1 ms 3676 KB Output is correct
17 Correct 2 ms 3672 KB Output is correct
18 Correct 2 ms 3676 KB Output is correct
19 Correct 2 ms 3676 KB Output is correct
20 Correct 2 ms 3676 KB Output is correct
21 Correct 2 ms 3676 KB Output is correct
22 Correct 2 ms 3676 KB Output is correct
23 Correct 1 ms 3676 KB Output is correct
24 Correct 2 ms 3676 KB Output is correct
25 Correct 3 ms 3932 KB Output is correct
26 Correct 2 ms 3928 KB Output is correct
27 Correct 5 ms 6492 KB Output is correct
28 Correct 5 ms 6492 KB Output is correct
29 Correct 3 ms 4808 KB Output is correct
30 Correct 4 ms 5216 KB Output is correct
31 Correct 4 ms 6492 KB Output is correct
32 Correct 4 ms 6328 KB Output is correct
33 Correct 5 ms 6492 KB Output is correct
34 Correct 5 ms 6492 KB Output is correct
35 Correct 2 ms 3676 KB Output is correct
36 Correct 3 ms 3676 KB Output is correct
37 Correct 5 ms 6236 KB Output is correct
38 Correct 5 ms 6352 KB Output is correct
39 Correct 3 ms 4700 KB Output is correct
40 Correct 3 ms 4700 KB Output is correct
41 Correct 7 ms 6236 KB Output is correct
42 Correct 7 ms 6200 KB Output is correct
43 Correct 2 ms 3728 KB Output is correct
44 Correct 2 ms 3676 KB Output is correct
45 Correct 5 ms 6236 KB Output is correct
46 Correct 6 ms 6492 KB Output is correct
47 Correct 3 ms 4700 KB Output is correct
48 Correct 3 ms 4696 KB Output is correct
49 Correct 5 ms 6236 KB Output is correct
50 Correct 5 ms 6316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3932 KB Output is correct
2 Correct 2 ms 3932 KB Output is correct
3 Correct 2 ms 3932 KB Output is correct
4 Correct 3 ms 3932 KB Output is correct
5 Correct 2 ms 3932 KB Output is correct
6 Correct 2 ms 4044 KB Output is correct
7 Correct 1 ms 3672 KB Output is correct
8 Correct 1 ms 3676 KB Output is correct
9 Correct 3 ms 3676 KB Output is correct
10 Correct 2 ms 3672 KB Output is correct
11 Correct 2 ms 3676 KB Output is correct
12 Correct 2 ms 3676 KB Output is correct
13 Correct 2 ms 3676 KB Output is correct
14 Correct 2 ms 3676 KB Output is correct
15 Correct 1 ms 3676 KB Output is correct
16 Correct 1 ms 3676 KB Output is correct
17 Correct 2 ms 3672 KB Output is correct
18 Correct 2 ms 3676 KB Output is correct
19 Correct 2 ms 3676 KB Output is correct
20 Correct 2 ms 3676 KB Output is correct
21 Correct 2 ms 3676 KB Output is correct
22 Correct 2 ms 3676 KB Output is correct
23 Correct 1 ms 3676 KB Output is correct
24 Correct 2 ms 3676 KB Output is correct
25 Correct 40 ms 16208 KB Output is correct
26 Correct 41 ms 16208 KB Output is correct
27 Correct 54 ms 19028 KB Output is correct
28 Correct 57 ms 19180 KB Output is correct
29 Correct 41 ms 19028 KB Output is correct
30 Correct 41 ms 19024 KB Output is correct
31 Correct 6 ms 6488 KB Output is correct
32 Correct 7 ms 6488 KB Output is correct
33 Correct 6 ms 6488 KB Output is correct
34 Correct 7 ms 6492 KB Output is correct
35 Correct 44 ms 9992 KB Output is correct
36 Correct 41 ms 10348 KB Output is correct
37 Correct 54 ms 12880 KB Output is correct
38 Correct 55 ms 13400 KB Output is correct
39 Correct 39 ms 13140 KB Output is correct
40 Correct 40 ms 12884 KB Output is correct
41 Correct 7 ms 5724 KB Output is correct
42 Correct 9 ms 5724 KB Output is correct
43 Correct 41 ms 9556 KB Output is correct
44 Correct 41 ms 9552 KB Output is correct
45 Correct 55 ms 12380 KB Output is correct
46 Correct 57 ms 12368 KB Output is correct
47 Correct 49 ms 12404 KB Output is correct
48 Correct 38 ms 12112 KB Output is correct
49 Correct 7 ms 5464 KB Output is correct
50 Correct 7 ms 5468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3932 KB Output is correct
2 Correct 2 ms 3932 KB Output is correct
3 Correct 2 ms 3932 KB Output is correct
4 Correct 3 ms 3932 KB Output is correct
5 Correct 2 ms 3932 KB Output is correct
6 Correct 2 ms 4044 KB Output is correct
7 Correct 1 ms 3672 KB Output is correct
8 Correct 1 ms 3676 KB Output is correct
9 Correct 3 ms 3676 KB Output is correct
10 Correct 2 ms 3672 KB Output is correct
11 Correct 2 ms 3676 KB Output is correct
12 Correct 2 ms 3676 KB Output is correct
13 Correct 2 ms 3676 KB Output is correct
14 Correct 2 ms 3676 KB Output is correct
15 Correct 1 ms 3676 KB Output is correct
16 Correct 1 ms 3676 KB Output is correct
17 Correct 2 ms 3672 KB Output is correct
18 Correct 2 ms 3676 KB Output is correct
19 Correct 2 ms 3676 KB Output is correct
20 Correct 2 ms 3676 KB Output is correct
21 Correct 2 ms 3676 KB Output is correct
22 Correct 2 ms 3676 KB Output is correct
23 Correct 1 ms 3676 KB Output is correct
24 Correct 2 ms 3676 KB Output is correct
25 Correct 40 ms 16208 KB Output is correct
26 Correct 41 ms 16208 KB Output is correct
27 Correct 54 ms 19028 KB Output is correct
28 Correct 57 ms 19180 KB Output is correct
29 Correct 41 ms 19028 KB Output is correct
30 Correct 41 ms 19024 KB Output is correct
31 Correct 6 ms 6488 KB Output is correct
32 Correct 7 ms 6488 KB Output is correct
33 Correct 6 ms 6488 KB Output is correct
34 Correct 7 ms 6492 KB Output is correct
35 Correct 44 ms 9992 KB Output is correct
36 Correct 41 ms 10348 KB Output is correct
37 Correct 54 ms 12880 KB Output is correct
38 Correct 55 ms 13400 KB Output is correct
39 Correct 39 ms 13140 KB Output is correct
40 Correct 40 ms 12884 KB Output is correct
41 Correct 7 ms 5724 KB Output is correct
42 Correct 9 ms 5724 KB Output is correct
43 Correct 41 ms 9556 KB Output is correct
44 Correct 41 ms 9552 KB Output is correct
45 Correct 55 ms 12380 KB Output is correct
46 Correct 57 ms 12368 KB Output is correct
47 Correct 49 ms 12404 KB Output is correct
48 Correct 38 ms 12112 KB Output is correct
49 Correct 7 ms 5464 KB Output is correct
50 Correct 7 ms 5468 KB Output is correct
51 Correct 101 ms 31436 KB Output is correct
52 Correct 110 ms 31524 KB Output is correct
53 Correct 146 ms 38736 KB Output is correct
54 Correct 147 ms 38700 KB Output is correct
55 Correct 128 ms 38996 KB Output is correct
56 Correct 105 ms 38992 KB Output is correct
57 Correct 25 ms 13652 KB Output is correct
58 Correct 22 ms 13704 KB Output is correct
59 Correct 21 ms 13656 KB Output is correct
60 Correct 22 ms 13748 KB Output is correct
61 Correct 103 ms 16516 KB Output is correct
62 Correct 101 ms 16996 KB Output is correct
63 Correct 157 ms 23456 KB Output is correct
64 Correct 167 ms 23968 KB Output is correct
65 Correct 112 ms 24404 KB Output is correct
66 Correct 107 ms 23888 KB Output is correct
67 Correct 22 ms 10588 KB Output is correct
68 Correct 28 ms 10584 KB Output is correct
69 Correct 117 ms 14372 KB Output is correct
70 Correct 105 ms 14492 KB Output is correct
71 Correct 158 ms 21840 KB Output is correct
72 Correct 185 ms 22024 KB Output is correct
73 Correct 112 ms 21844 KB Output is correct
74 Correct 122 ms 21844 KB Output is correct
75 Correct 23 ms 10204 KB Output is correct
76 Correct 23 ms 10320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3932 KB Output is correct
2 Correct 2 ms 3932 KB Output is correct
3 Correct 2 ms 3932 KB Output is correct
4 Correct 3 ms 3932 KB Output is correct
5 Correct 2 ms 3932 KB Output is correct
6 Correct 2 ms 4044 KB Output is correct
7 Correct 1 ms 3672 KB Output is correct
8 Correct 1 ms 3676 KB Output is correct
9 Correct 3 ms 3676 KB Output is correct
10 Correct 2 ms 3672 KB Output is correct
11 Correct 2 ms 3676 KB Output is correct
12 Correct 2 ms 3676 KB Output is correct
13 Correct 2 ms 3676 KB Output is correct
14 Correct 2 ms 3676 KB Output is correct
15 Correct 1 ms 3676 KB Output is correct
16 Correct 1 ms 3676 KB Output is correct
17 Correct 2 ms 3672 KB Output is correct
18 Correct 2 ms 3676 KB Output is correct
19 Correct 2 ms 3676 KB Output is correct
20 Correct 2 ms 3676 KB Output is correct
21 Correct 2 ms 3676 KB Output is correct
22 Correct 2 ms 3676 KB Output is correct
23 Correct 1 ms 3676 KB Output is correct
24 Correct 2 ms 3676 KB Output is correct
25 Correct 3 ms 3932 KB Output is correct
26 Correct 2 ms 3928 KB Output is correct
27 Correct 5 ms 6492 KB Output is correct
28 Correct 5 ms 6492 KB Output is correct
29 Correct 3 ms 4808 KB Output is correct
30 Correct 4 ms 5216 KB Output is correct
31 Correct 4 ms 6492 KB Output is correct
32 Correct 4 ms 6328 KB Output is correct
33 Correct 5 ms 6492 KB Output is correct
34 Correct 5 ms 6492 KB Output is correct
35 Correct 2 ms 3676 KB Output is correct
36 Correct 3 ms 3676 KB Output is correct
37 Correct 5 ms 6236 KB Output is correct
38 Correct 5 ms 6352 KB Output is correct
39 Correct 3 ms 4700 KB Output is correct
40 Correct 3 ms 4700 KB Output is correct
41 Correct 7 ms 6236 KB Output is correct
42 Correct 7 ms 6200 KB Output is correct
43 Correct 2 ms 3728 KB Output is correct
44 Correct 2 ms 3676 KB Output is correct
45 Correct 5 ms 6236 KB Output is correct
46 Correct 6 ms 6492 KB Output is correct
47 Correct 3 ms 4700 KB Output is correct
48 Correct 3 ms 4696 KB Output is correct
49 Correct 5 ms 6236 KB Output is correct
50 Correct 5 ms 6316 KB Output is correct
51 Correct 40 ms 16208 KB Output is correct
52 Correct 41 ms 16208 KB Output is correct
53 Correct 54 ms 19028 KB Output is correct
54 Correct 57 ms 19180 KB Output is correct
55 Correct 41 ms 19028 KB Output is correct
56 Correct 41 ms 19024 KB Output is correct
57 Correct 6 ms 6488 KB Output is correct
58 Correct 7 ms 6488 KB Output is correct
59 Correct 6 ms 6488 KB Output is correct
60 Correct 7 ms 6492 KB Output is correct
61 Correct 44 ms 9992 KB Output is correct
62 Correct 41 ms 10348 KB Output is correct
63 Correct 54 ms 12880 KB Output is correct
64 Correct 55 ms 13400 KB Output is correct
65 Correct 39 ms 13140 KB Output is correct
66 Correct 40 ms 12884 KB Output is correct
67 Correct 7 ms 5724 KB Output is correct
68 Correct 9 ms 5724 KB Output is correct
69 Correct 41 ms 9556 KB Output is correct
70 Correct 41 ms 9552 KB Output is correct
71 Correct 55 ms 12380 KB Output is correct
72 Correct 57 ms 12368 KB Output is correct
73 Correct 49 ms 12404 KB Output is correct
74 Correct 38 ms 12112 KB Output is correct
75 Correct 7 ms 5464 KB Output is correct
76 Correct 7 ms 5468 KB Output is correct
77 Correct 101 ms 31436 KB Output is correct
78 Correct 110 ms 31524 KB Output is correct
79 Correct 146 ms 38736 KB Output is correct
80 Correct 147 ms 38700 KB Output is correct
81 Correct 128 ms 38996 KB Output is correct
82 Correct 105 ms 38992 KB Output is correct
83 Correct 25 ms 13652 KB Output is correct
84 Correct 22 ms 13704 KB Output is correct
85 Correct 21 ms 13656 KB Output is correct
86 Correct 22 ms 13748 KB Output is correct
87 Correct 103 ms 16516 KB Output is correct
88 Correct 101 ms 16996 KB Output is correct
89 Correct 157 ms 23456 KB Output is correct
90 Correct 167 ms 23968 KB Output is correct
91 Correct 112 ms 24404 KB Output is correct
92 Correct 107 ms 23888 KB Output is correct
93 Correct 22 ms 10588 KB Output is correct
94 Correct 28 ms 10584 KB Output is correct
95 Correct 117 ms 14372 KB Output is correct
96 Correct 105 ms 14492 KB Output is correct
97 Correct 158 ms 21840 KB Output is correct
98 Correct 185 ms 22024 KB Output is correct
99 Correct 112 ms 21844 KB Output is correct
100 Correct 122 ms 21844 KB Output is correct
101 Correct 23 ms 10204 KB Output is correct
102 Correct 23 ms 10320 KB Output is correct
103 Correct 122 ms 32852 KB Output is correct
104 Correct 119 ms 32856 KB Output is correct
105 Correct 519 ms 193292 KB Output is correct
106 Correct 496 ms 193104 KB Output is correct
107 Correct 241 ms 100620 KB Output is correct
108 Correct 251 ms 100616 KB Output is correct
109 Correct 61 ms 47956 KB Output is correct
110 Correct 65 ms 48080 KB Output is correct
111 Correct 62 ms 47868 KB Output is correct
112 Correct 62 ms 47836 KB Output is correct
113 Correct 126 ms 18660 KB Output is correct
114 Correct 135 ms 18432 KB Output is correct
115 Correct 445 ms 178332 KB Output is correct
116 Correct 431 ms 178964 KB Output is correct
117 Correct 203 ms 85864 KB Output is correct
118 Correct 210 ms 85612 KB Output is correct
119 Correct 62 ms 45188 KB Output is correct
120 Correct 59 ms 44880 KB Output is correct
121 Correct 127 ms 15700 KB Output is correct
122 Correct 138 ms 15880 KB Output is correct
123 Correct 408 ms 176000 KB Output is correct
124 Correct 424 ms 176320 KB Output is correct
125 Correct 217 ms 83496 KB Output is correct
126 Correct 196 ms 83356 KB Output is correct
127 Correct 61 ms 44568 KB Output is correct
128 Correct 62 ms 44440 KB Output is correct