Submission #850726

# Submission time Handle Problem Language Result Execution time Memory
850726 2023-09-17T10:59:26 Z TahirAliyev Vinjete (COI22_vinjete) C++17
100 / 100
672 ms 252360 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
#define oo 2e9
#define pii pair<ll, int>

const int MAX = 1e5 + 5, LOGMAX = 31, treesize = MAX * LOGMAX * 4;
int n, m;
vector<array<int, 3>> g[MAX];

pii tree[treesize];
int L[treesize], R[treesize], lazy[treesize];
int nxt = 2;

void relax(int node, int l, int r){
    if(!lazy[node]) return;
    tree[node].first += lazy[node];
    if(l == r){
        lazy[node] = 0;
        return;
    }
    int mid = (l + r) / 2;
    if(!L[node]){
        L[node] = nxt++;
        tree[L[node]] = {0, mid - l + 1};
    }
    if(!R[node]){
        R[node] = nxt++;
        tree[R[node]] = {0, r - mid};
    }
    lazy[L[node]] += lazy[node];
    lazy[R[node]] += lazy[node];
    lazy[node] = 0;
}


pii combine(pii a, pii b){
    if(a.first == b.first){
        return {a.first, a.second + b.second};
    }
    return min(a, b);
}

void update(int node, int l, int r, int ul, int ur, int val){
    relax(node, l, r);
    if(ur < l || r < ul) return;
    if(ul <= l && r <= ur){
        lazy[node] += val;
        relax(node, l, r);
        return;
    }
    int mid = (l + r) / 2;
    if(!L[node]){
        L[node] = nxt++;    
        tree[L[node]] = {0, mid - l + 1};
    }   
    if(!R[node]){
        R[node] = nxt++;
        tree[R[node]] = {0, r - mid};
    }
    update(L[node], l, mid, ul, ur, val);
    update(R[node], mid + 1, r, ul, ur, val);
    tree[node] = combine(tree[L[node]], tree[R[node]]);
}

int ans[MAX];

void dfs(int node, int p, int l, int r){
    if(node != 1){
        update(1, 1, m, l, r, 1);
    }
    if(tree[1].first == 0){
        ans[node] = m - tree[1].second;
    }
    else{
        ans[node] = m;
    }
    for(auto to : g[node]){
        if(p == to[0]) continue;
        dfs(to[0], node, to[1], to[2]);
    }
    if(node != 1){
        update(1, 1, m, l, r, -1);
    }
}


int main(){
    cin >> n >> m;
    for(int i = 1; i < n; i++){
        int a, b, l, r; cin >> a >> b >> l >> r;
        g[a].push_back({b, l, r});
        g[b].push_back({a, l, r});
    }
    tree[1] = {0, m};
    dfs(1, 1, 0, 0);
    for(int i = 2; i <= n; i++){
        cout << ans[i] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6232 KB Output is correct
2 Correct 3 ms 6232 KB Output is correct
3 Correct 3 ms 6236 KB Output is correct
4 Correct 3 ms 6232 KB Output is correct
5 Correct 3 ms 6232 KB Output is correct
6 Correct 3 ms 6232 KB Output is correct
7 Correct 2 ms 6236 KB Output is correct
8 Correct 2 ms 6232 KB Output is correct
9 Correct 4 ms 6232 KB Output is correct
10 Correct 3 ms 6232 KB Output is correct
11 Correct 4 ms 6232 KB Output is correct
12 Correct 3 ms 6232 KB Output is correct
13 Correct 3 ms 6232 KB Output is correct
14 Correct 3 ms 6236 KB Output is correct
15 Correct 2 ms 6236 KB Output is correct
16 Correct 2 ms 6232 KB Output is correct
17 Correct 3 ms 6232 KB Output is correct
18 Correct 3 ms 6232 KB Output is correct
19 Correct 3 ms 6232 KB Output is correct
20 Correct 3 ms 6232 KB Output is correct
21 Correct 4 ms 6232 KB Output is correct
22 Correct 3 ms 6232 KB Output is correct
23 Correct 2 ms 6232 KB Output is correct
24 Correct 2 ms 6232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6232 KB Output is correct
2 Correct 3 ms 6232 KB Output is correct
3 Correct 3 ms 6236 KB Output is correct
4 Correct 3 ms 6232 KB Output is correct
5 Correct 3 ms 6232 KB Output is correct
6 Correct 3 ms 6232 KB Output is correct
7 Correct 2 ms 6236 KB Output is correct
8 Correct 2 ms 6232 KB Output is correct
9 Correct 4 ms 6232 KB Output is correct
10 Correct 3 ms 6232 KB Output is correct
11 Correct 4 ms 6232 KB Output is correct
12 Correct 3 ms 6232 KB Output is correct
13 Correct 3 ms 6232 KB Output is correct
14 Correct 3 ms 6236 KB Output is correct
15 Correct 2 ms 6236 KB Output is correct
16 Correct 2 ms 6232 KB Output is correct
17 Correct 3 ms 6232 KB Output is correct
18 Correct 3 ms 6232 KB Output is correct
19 Correct 3 ms 6232 KB Output is correct
20 Correct 3 ms 6232 KB Output is correct
21 Correct 4 ms 6232 KB Output is correct
22 Correct 3 ms 6232 KB Output is correct
23 Correct 2 ms 6232 KB Output is correct
24 Correct 2 ms 6232 KB Output is correct
25 Correct 5 ms 6232 KB Output is correct
26 Correct 4 ms 6232 KB Output is correct
27 Correct 6 ms 9816 KB Output is correct
28 Correct 7 ms 9816 KB Output is correct
29 Correct 5 ms 6744 KB Output is correct
30 Correct 4 ms 6744 KB Output is correct
31 Correct 6 ms 7512 KB Output is correct
32 Correct 5 ms 7516 KB Output is correct
33 Correct 5 ms 7512 KB Output is correct
34 Correct 6 ms 7516 KB Output is correct
35 Correct 5 ms 6232 KB Output is correct
36 Correct 4 ms 6232 KB Output is correct
37 Correct 6 ms 9816 KB Output is correct
38 Correct 6 ms 9816 KB Output is correct
39 Correct 4 ms 6748 KB Output is correct
40 Correct 4 ms 6744 KB Output is correct
41 Correct 5 ms 7512 KB Output is correct
42 Correct 5 ms 7512 KB Output is correct
43 Correct 5 ms 6232 KB Output is correct
44 Correct 5 ms 6236 KB Output is correct
45 Correct 6 ms 9816 KB Output is correct
46 Correct 6 ms 9816 KB Output is correct
47 Correct 5 ms 6744 KB Output is correct
48 Correct 4 ms 6744 KB Output is correct
49 Correct 6 ms 7512 KB Output is correct
50 Correct 5 ms 7512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6232 KB Output is correct
2 Correct 3 ms 6232 KB Output is correct
3 Correct 3 ms 6236 KB Output is correct
4 Correct 3 ms 6232 KB Output is correct
5 Correct 3 ms 6232 KB Output is correct
6 Correct 3 ms 6232 KB Output is correct
7 Correct 2 ms 6236 KB Output is correct
8 Correct 2 ms 6232 KB Output is correct
9 Correct 4 ms 6232 KB Output is correct
10 Correct 3 ms 6232 KB Output is correct
11 Correct 4 ms 6232 KB Output is correct
12 Correct 3 ms 6232 KB Output is correct
13 Correct 3 ms 6232 KB Output is correct
14 Correct 3 ms 6236 KB Output is correct
15 Correct 2 ms 6236 KB Output is correct
16 Correct 2 ms 6232 KB Output is correct
17 Correct 3 ms 6232 KB Output is correct
18 Correct 3 ms 6232 KB Output is correct
19 Correct 3 ms 6232 KB Output is correct
20 Correct 3 ms 6232 KB Output is correct
21 Correct 4 ms 6232 KB Output is correct
22 Correct 3 ms 6232 KB Output is correct
23 Correct 2 ms 6232 KB Output is correct
24 Correct 2 ms 6232 KB Output is correct
25 Correct 79 ms 10320 KB Output is correct
26 Correct 80 ms 10240 KB Output is correct
27 Correct 95 ms 11088 KB Output is correct
28 Correct 95 ms 11052 KB Output is correct
29 Correct 66 ms 11136 KB Output is correct
30 Correct 65 ms 11088 KB Output is correct
31 Correct 11 ms 7256 KB Output is correct
32 Correct 9 ms 7328 KB Output is correct
33 Correct 9 ms 7260 KB Output is correct
34 Correct 10 ms 7260 KB Output is correct
35 Correct 78 ms 8424 KB Output is correct
36 Correct 78 ms 8528 KB Output is correct
37 Correct 91 ms 9356 KB Output is correct
38 Correct 102 ms 9540 KB Output is correct
39 Correct 65 ms 9296 KB Output is correct
40 Correct 64 ms 9040 KB Output is correct
41 Correct 11 ms 7000 KB Output is correct
42 Correct 10 ms 7000 KB Output is correct
43 Correct 82 ms 8276 KB Output is correct
44 Correct 88 ms 8068 KB Output is correct
45 Correct 91 ms 9100 KB Output is correct
46 Correct 102 ms 9044 KB Output is correct
47 Correct 72 ms 9056 KB Output is correct
48 Correct 66 ms 9040 KB Output is correct
49 Correct 10 ms 7256 KB Output is correct
50 Correct 9 ms 7000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6232 KB Output is correct
2 Correct 3 ms 6232 KB Output is correct
3 Correct 3 ms 6236 KB Output is correct
4 Correct 3 ms 6232 KB Output is correct
5 Correct 3 ms 6232 KB Output is correct
6 Correct 3 ms 6232 KB Output is correct
7 Correct 2 ms 6236 KB Output is correct
8 Correct 2 ms 6232 KB Output is correct
9 Correct 4 ms 6232 KB Output is correct
10 Correct 3 ms 6232 KB Output is correct
11 Correct 4 ms 6232 KB Output is correct
12 Correct 3 ms 6232 KB Output is correct
13 Correct 3 ms 6232 KB Output is correct
14 Correct 3 ms 6236 KB Output is correct
15 Correct 2 ms 6236 KB Output is correct
16 Correct 2 ms 6232 KB Output is correct
17 Correct 3 ms 6232 KB Output is correct
18 Correct 3 ms 6232 KB Output is correct
19 Correct 3 ms 6232 KB Output is correct
20 Correct 3 ms 6232 KB Output is correct
21 Correct 4 ms 6232 KB Output is correct
22 Correct 3 ms 6232 KB Output is correct
23 Correct 2 ms 6232 KB Output is correct
24 Correct 2 ms 6232 KB Output is correct
25 Correct 79 ms 10320 KB Output is correct
26 Correct 80 ms 10240 KB Output is correct
27 Correct 95 ms 11088 KB Output is correct
28 Correct 95 ms 11052 KB Output is correct
29 Correct 66 ms 11136 KB Output is correct
30 Correct 65 ms 11088 KB Output is correct
31 Correct 11 ms 7256 KB Output is correct
32 Correct 9 ms 7328 KB Output is correct
33 Correct 9 ms 7260 KB Output is correct
34 Correct 10 ms 7260 KB Output is correct
35 Correct 78 ms 8424 KB Output is correct
36 Correct 78 ms 8528 KB Output is correct
37 Correct 91 ms 9356 KB Output is correct
38 Correct 102 ms 9540 KB Output is correct
39 Correct 65 ms 9296 KB Output is correct
40 Correct 64 ms 9040 KB Output is correct
41 Correct 11 ms 7000 KB Output is correct
42 Correct 10 ms 7000 KB Output is correct
43 Correct 82 ms 8276 KB Output is correct
44 Correct 88 ms 8068 KB Output is correct
45 Correct 91 ms 9100 KB Output is correct
46 Correct 102 ms 9044 KB Output is correct
47 Correct 72 ms 9056 KB Output is correct
48 Correct 66 ms 9040 KB Output is correct
49 Correct 10 ms 7256 KB Output is correct
50 Correct 9 ms 7000 KB Output is correct
51 Correct 208 ms 16664 KB Output is correct
52 Correct 205 ms 16464 KB Output is correct
53 Correct 259 ms 20928 KB Output is correct
54 Correct 256 ms 20816 KB Output is correct
55 Correct 173 ms 20800 KB Output is correct
56 Correct 171 ms 20816 KB Output is correct
57 Correct 34 ms 12112 KB Output is correct
58 Correct 35 ms 12112 KB Output is correct
59 Correct 35 ms 12124 KB Output is correct
60 Correct 35 ms 12116 KB Output is correct
61 Correct 209 ms 12244 KB Output is correct
62 Correct 204 ms 12112 KB Output is correct
63 Correct 257 ms 16432 KB Output is correct
64 Correct 254 ms 16208 KB Output is correct
65 Correct 183 ms 16464 KB Output is correct
66 Correct 174 ms 15936 KB Output is correct
67 Correct 35 ms 11180 KB Output is correct
68 Correct 35 ms 11088 KB Output is correct
69 Correct 207 ms 11352 KB Output is correct
70 Correct 209 ms 11344 KB Output is correct
71 Correct 264 ms 15952 KB Output is correct
72 Correct 249 ms 15712 KB Output is correct
73 Correct 171 ms 15264 KB Output is correct
74 Correct 174 ms 15176 KB Output is correct
75 Correct 35 ms 10832 KB Output is correct
76 Correct 36 ms 10832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6232 KB Output is correct
2 Correct 3 ms 6232 KB Output is correct
3 Correct 3 ms 6236 KB Output is correct
4 Correct 3 ms 6232 KB Output is correct
5 Correct 3 ms 6232 KB Output is correct
6 Correct 3 ms 6232 KB Output is correct
7 Correct 2 ms 6236 KB Output is correct
8 Correct 2 ms 6232 KB Output is correct
9 Correct 4 ms 6232 KB Output is correct
10 Correct 3 ms 6232 KB Output is correct
11 Correct 4 ms 6232 KB Output is correct
12 Correct 3 ms 6232 KB Output is correct
13 Correct 3 ms 6232 KB Output is correct
14 Correct 3 ms 6236 KB Output is correct
15 Correct 2 ms 6236 KB Output is correct
16 Correct 2 ms 6232 KB Output is correct
17 Correct 3 ms 6232 KB Output is correct
18 Correct 3 ms 6232 KB Output is correct
19 Correct 3 ms 6232 KB Output is correct
20 Correct 3 ms 6232 KB Output is correct
21 Correct 4 ms 6232 KB Output is correct
22 Correct 3 ms 6232 KB Output is correct
23 Correct 2 ms 6232 KB Output is correct
24 Correct 2 ms 6232 KB Output is correct
25 Correct 5 ms 6232 KB Output is correct
26 Correct 4 ms 6232 KB Output is correct
27 Correct 6 ms 9816 KB Output is correct
28 Correct 7 ms 9816 KB Output is correct
29 Correct 5 ms 6744 KB Output is correct
30 Correct 4 ms 6744 KB Output is correct
31 Correct 6 ms 7512 KB Output is correct
32 Correct 5 ms 7516 KB Output is correct
33 Correct 5 ms 7512 KB Output is correct
34 Correct 6 ms 7516 KB Output is correct
35 Correct 5 ms 6232 KB Output is correct
36 Correct 4 ms 6232 KB Output is correct
37 Correct 6 ms 9816 KB Output is correct
38 Correct 6 ms 9816 KB Output is correct
39 Correct 4 ms 6748 KB Output is correct
40 Correct 4 ms 6744 KB Output is correct
41 Correct 5 ms 7512 KB Output is correct
42 Correct 5 ms 7512 KB Output is correct
43 Correct 5 ms 6232 KB Output is correct
44 Correct 5 ms 6236 KB Output is correct
45 Correct 6 ms 9816 KB Output is correct
46 Correct 6 ms 9816 KB Output is correct
47 Correct 5 ms 6744 KB Output is correct
48 Correct 4 ms 6744 KB Output is correct
49 Correct 6 ms 7512 KB Output is correct
50 Correct 5 ms 7512 KB Output is correct
51 Correct 79 ms 10320 KB Output is correct
52 Correct 80 ms 10240 KB Output is correct
53 Correct 95 ms 11088 KB Output is correct
54 Correct 95 ms 11052 KB Output is correct
55 Correct 66 ms 11136 KB Output is correct
56 Correct 65 ms 11088 KB Output is correct
57 Correct 11 ms 7256 KB Output is correct
58 Correct 9 ms 7328 KB Output is correct
59 Correct 9 ms 7260 KB Output is correct
60 Correct 10 ms 7260 KB Output is correct
61 Correct 78 ms 8424 KB Output is correct
62 Correct 78 ms 8528 KB Output is correct
63 Correct 91 ms 9356 KB Output is correct
64 Correct 102 ms 9540 KB Output is correct
65 Correct 65 ms 9296 KB Output is correct
66 Correct 64 ms 9040 KB Output is correct
67 Correct 11 ms 7000 KB Output is correct
68 Correct 10 ms 7000 KB Output is correct
69 Correct 82 ms 8276 KB Output is correct
70 Correct 88 ms 8068 KB Output is correct
71 Correct 91 ms 9100 KB Output is correct
72 Correct 102 ms 9044 KB Output is correct
73 Correct 72 ms 9056 KB Output is correct
74 Correct 66 ms 9040 KB Output is correct
75 Correct 10 ms 7256 KB Output is correct
76 Correct 9 ms 7000 KB Output is correct
77 Correct 208 ms 16664 KB Output is correct
78 Correct 205 ms 16464 KB Output is correct
79 Correct 259 ms 20928 KB Output is correct
80 Correct 256 ms 20816 KB Output is correct
81 Correct 173 ms 20800 KB Output is correct
82 Correct 171 ms 20816 KB Output is correct
83 Correct 34 ms 12112 KB Output is correct
84 Correct 35 ms 12112 KB Output is correct
85 Correct 35 ms 12124 KB Output is correct
86 Correct 35 ms 12116 KB Output is correct
87 Correct 209 ms 12244 KB Output is correct
88 Correct 204 ms 12112 KB Output is correct
89 Correct 257 ms 16432 KB Output is correct
90 Correct 254 ms 16208 KB Output is correct
91 Correct 183 ms 16464 KB Output is correct
92 Correct 174 ms 15936 KB Output is correct
93 Correct 35 ms 11180 KB Output is correct
94 Correct 35 ms 11088 KB Output is correct
95 Correct 207 ms 11352 KB Output is correct
96 Correct 209 ms 11344 KB Output is correct
97 Correct 264 ms 15952 KB Output is correct
98 Correct 249 ms 15712 KB Output is correct
99 Correct 171 ms 15264 KB Output is correct
100 Correct 174 ms 15176 KB Output is correct
101 Correct 35 ms 10832 KB Output is correct
102 Correct 36 ms 10832 KB Output is correct
103 Correct 299 ms 17016 KB Output is correct
104 Correct 298 ms 16976 KB Output is correct
105 Correct 672 ms 252360 KB Output is correct
106 Correct 650 ms 252092 KB Output is correct
107 Correct 314 ms 88912 KB Output is correct
108 Correct 319 ms 89348 KB Output is correct
109 Correct 82 ms 53328 KB Output is correct
110 Correct 75 ms 51792 KB Output is correct
111 Correct 83 ms 51700 KB Output is correct
112 Correct 75 ms 51664 KB Output is correct
113 Correct 308 ms 12600 KB Output is correct
114 Correct 301 ms 12448 KB Output is correct
115 Correct 549 ms 247532 KB Output is correct
116 Correct 567 ms 247632 KB Output is correct
117 Correct 295 ms 84304 KB Output is correct
118 Correct 320 ms 84048 KB Output is correct
119 Correct 71 ms 50768 KB Output is correct
120 Correct 72 ms 50768 KB Output is correct
121 Correct 319 ms 11696 KB Output is correct
122 Correct 305 ms 11856 KB Output is correct
123 Correct 558 ms 244152 KB Output is correct
124 Correct 566 ms 246896 KB Output is correct
125 Correct 301 ms 83776 KB Output is correct
126 Correct 302 ms 83508 KB Output is correct
127 Correct 73 ms 50512 KB Output is correct
128 Correct 83 ms 50564 KB Output is correct