Submission #1019014

# Submission time Handle Problem Language Result Execution time Memory
1019014 2024-07-10T12:00:38 Z MarwenElarbi Vinjete (COI22_vinjete) C++17
100 / 100
473 ms 150876 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define pb push_back
#define se second
#define fi first
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int nax=1e5+5;
struct edge{
    int x,l,r;
};
vector<edge> adj[nax];
struct node{
    int ans,lazy,cnt,tl,tr,l,r;
    node () : ans(0), lazy(0),cnt (0), l(-1), r(-1) {}
};
node segtree[nax*50];
int cnt=1;
int res[nax];
void push_lazy(int pos){
    if(segtree[pos].lazy==0) return;
    int mid=(segtree[pos].tl+segtree[pos].tr)/2;
    if(segtree[pos].l==-1){
        segtree[pos].l=cnt++;
        segtree[segtree[pos].l].tl=segtree[pos].tl;
        segtree[segtree[pos].l].tr=mid;
    }
    if(segtree[pos].r==-1){
        segtree[pos].r=cnt++;
        segtree[segtree[pos].r].tl=mid+1;
        segtree[segtree[pos].r].tr=segtree[pos].tr;
    }
    segtree[pos].lazy=0;
}
void update(int pos,int l,int r,int value){
    push_lazy(pos);
    //cout <<l<<" "<<r<<" "<<pos<<endl;
    if(l==segtree[pos].tl&&r==segtree[pos].tr){
        segtree[pos].cnt+=value;
        if(segtree[pos].cnt) segtree[pos].ans=(segtree[pos].tr-segtree[pos].tl+1);
        else segtree[pos].ans=segtree[segtree[pos].l].ans+segtree[segtree[pos].r].ans;
        push_lazy(pos);
        return;
    }
    int mid=(segtree[pos].tl+segtree[pos].tr)/2;
    //cout <<segtree[pos].tl<<" "<<segtree[pos].tr<<endl;
    if(segtree[pos].l==-1){
        segtree[pos].l=cnt++;
        segtree[segtree[pos].l].tl=segtree[pos].tl;
        segtree[segtree[pos].l].tr=mid;
    }
    if(segtree[pos].r==-1){
        segtree[pos].r=cnt++;
        segtree[segtree[pos].r].tl=mid+1;
        segtree[segtree[pos].r].tr=segtree[pos].tr;
    }
    if(l>mid) update(segtree[pos].r,l,r,value);
    else if(r<=mid) update(segtree[pos].l,l,r,value);
    else{
        update(segtree[pos].l,l,mid,value);
        update(segtree[pos].r,mid+1,r,value);
    }
    push_lazy(segtree[pos].l);
    push_lazy(segtree[pos].r);
    //cout <<segtree[pos].tl<<" "<<segtree[pos].tr<<" "<<segtree[segtree[pos].l].ans<<" "<<segtree[segtree[pos].r].cnt<<endl;
    segtree[pos].ans=(segtree[pos].cnt ? segtree[pos].tr-segtree[pos].tl+1 : segtree[segtree[pos].l].ans+segtree[segtree[pos].r].ans);
}
void dfs(int x,int p){
    res[x]=segtree[0].ans;
    for(auto u:adj[x]){
        if(p==u.x) continue;
        update(0,u.l,u.r,1);
        dfs(u.x,x);
        update(0,u.l,u.r,-1);
    }
    return;
}
int main() {
    optimise;
    int n,m;
    cin>>n>>m;
    for (int i = 0; i < n-1; ++i)
    {
        int x,y,l,r;
        cin>>x>>y>>l>>r;
        x--;y--;
        adj[x].pb({y,l,r});
        adj[y].pb({x,l,r});
    }
    segtree[0].tl=0;
    segtree[0].tr=1e9;
    dfs(0,-1);
    for (int i = 1; i < n; ++i)
    {
        cout <<res[i]<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 57 ms 139792 KB Output is correct
2 Correct 52 ms 139760 KB Output is correct
3 Correct 53 ms 139852 KB Output is correct
4 Correct 51 ms 139600 KB Output is correct
5 Correct 51 ms 139600 KB Output is correct
6 Correct 52 ms 139700 KB Output is correct
7 Correct 49 ms 139612 KB Output is correct
8 Correct 54 ms 139680 KB Output is correct
9 Correct 52 ms 139752 KB Output is correct
10 Correct 53 ms 139712 KB Output is correct
11 Correct 50 ms 139600 KB Output is correct
12 Correct 56 ms 139600 KB Output is correct
13 Correct 52 ms 139604 KB Output is correct
14 Correct 50 ms 139596 KB Output is correct
15 Correct 52 ms 139600 KB Output is correct
16 Correct 51 ms 139604 KB Output is correct
17 Correct 53 ms 139604 KB Output is correct
18 Correct 50 ms 139604 KB Output is correct
19 Correct 50 ms 139604 KB Output is correct
20 Correct 55 ms 139604 KB Output is correct
21 Correct 50 ms 139584 KB Output is correct
22 Correct 55 ms 139652 KB Output is correct
23 Correct 48 ms 139696 KB Output is correct
24 Correct 53 ms 139600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 139792 KB Output is correct
2 Correct 52 ms 139760 KB Output is correct
3 Correct 53 ms 139852 KB Output is correct
4 Correct 51 ms 139600 KB Output is correct
5 Correct 51 ms 139600 KB Output is correct
6 Correct 52 ms 139700 KB Output is correct
7 Correct 49 ms 139612 KB Output is correct
8 Correct 54 ms 139680 KB Output is correct
9 Correct 52 ms 139752 KB Output is correct
10 Correct 53 ms 139712 KB Output is correct
11 Correct 50 ms 139600 KB Output is correct
12 Correct 56 ms 139600 KB Output is correct
13 Correct 52 ms 139604 KB Output is correct
14 Correct 50 ms 139596 KB Output is correct
15 Correct 52 ms 139600 KB Output is correct
16 Correct 51 ms 139604 KB Output is correct
17 Correct 53 ms 139604 KB Output is correct
18 Correct 50 ms 139604 KB Output is correct
19 Correct 50 ms 139604 KB Output is correct
20 Correct 55 ms 139604 KB Output is correct
21 Correct 50 ms 139584 KB Output is correct
22 Correct 55 ms 139652 KB Output is correct
23 Correct 48 ms 139696 KB Output is correct
24 Correct 53 ms 139600 KB Output is correct
25 Correct 51 ms 139604 KB Output is correct
26 Correct 51 ms 139604 KB Output is correct
27 Correct 51 ms 139604 KB Output is correct
28 Correct 52 ms 139860 KB Output is correct
29 Correct 50 ms 139600 KB Output is correct
30 Correct 50 ms 139604 KB Output is correct
31 Correct 51 ms 139600 KB Output is correct
32 Correct 51 ms 139856 KB Output is correct
33 Correct 51 ms 139656 KB Output is correct
34 Correct 52 ms 139780 KB Output is correct
35 Correct 51 ms 139600 KB Output is correct
36 Correct 52 ms 139600 KB Output is correct
37 Correct 54 ms 139640 KB Output is correct
38 Correct 55 ms 139604 KB Output is correct
39 Correct 51 ms 139604 KB Output is correct
40 Correct 51 ms 139604 KB Output is correct
41 Correct 51 ms 139604 KB Output is correct
42 Correct 51 ms 139816 KB Output is correct
43 Correct 52 ms 139604 KB Output is correct
44 Correct 54 ms 139604 KB Output is correct
45 Correct 53 ms 139600 KB Output is correct
46 Correct 52 ms 139604 KB Output is correct
47 Correct 51 ms 139600 KB Output is correct
48 Correct 50 ms 139760 KB Output is correct
49 Correct 51 ms 139600 KB Output is correct
50 Correct 52 ms 139600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 139792 KB Output is correct
2 Correct 52 ms 139760 KB Output is correct
3 Correct 53 ms 139852 KB Output is correct
4 Correct 51 ms 139600 KB Output is correct
5 Correct 51 ms 139600 KB Output is correct
6 Correct 52 ms 139700 KB Output is correct
7 Correct 49 ms 139612 KB Output is correct
8 Correct 54 ms 139680 KB Output is correct
9 Correct 52 ms 139752 KB Output is correct
10 Correct 53 ms 139712 KB Output is correct
11 Correct 50 ms 139600 KB Output is correct
12 Correct 56 ms 139600 KB Output is correct
13 Correct 52 ms 139604 KB Output is correct
14 Correct 50 ms 139596 KB Output is correct
15 Correct 52 ms 139600 KB Output is correct
16 Correct 51 ms 139604 KB Output is correct
17 Correct 53 ms 139604 KB Output is correct
18 Correct 50 ms 139604 KB Output is correct
19 Correct 50 ms 139604 KB Output is correct
20 Correct 55 ms 139604 KB Output is correct
21 Correct 50 ms 139584 KB Output is correct
22 Correct 55 ms 139652 KB Output is correct
23 Correct 48 ms 139696 KB Output is correct
24 Correct 53 ms 139600 KB Output is correct
25 Correct 132 ms 142672 KB Output is correct
26 Correct 133 ms 142676 KB Output is correct
27 Correct 146 ms 142672 KB Output is correct
28 Correct 152 ms 142672 KB Output is correct
29 Correct 128 ms 142676 KB Output is correct
30 Correct 126 ms 142680 KB Output is correct
31 Correct 59 ms 139968 KB Output is correct
32 Correct 63 ms 140116 KB Output is correct
33 Correct 57 ms 139964 KB Output is correct
34 Correct 58 ms 140100 KB Output is correct
35 Correct 134 ms 141908 KB Output is correct
36 Correct 134 ms 141908 KB Output is correct
37 Correct 150 ms 141904 KB Output is correct
38 Correct 144 ms 141844 KB Output is correct
39 Correct 129 ms 141652 KB Output is correct
40 Correct 125 ms 141800 KB Output is correct
41 Correct 58 ms 139860 KB Output is correct
42 Correct 63 ms 139860 KB Output is correct
43 Correct 137 ms 141660 KB Output is correct
44 Correct 136 ms 141652 KB Output is correct
45 Correct 150 ms 141668 KB Output is correct
46 Correct 148 ms 141740 KB Output is correct
47 Correct 130 ms 141652 KB Output is correct
48 Correct 125 ms 141636 KB Output is correct
49 Correct 61 ms 139856 KB Output is correct
50 Correct 60 ms 139856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 139792 KB Output is correct
2 Correct 52 ms 139760 KB Output is correct
3 Correct 53 ms 139852 KB Output is correct
4 Correct 51 ms 139600 KB Output is correct
5 Correct 51 ms 139600 KB Output is correct
6 Correct 52 ms 139700 KB Output is correct
7 Correct 49 ms 139612 KB Output is correct
8 Correct 54 ms 139680 KB Output is correct
9 Correct 52 ms 139752 KB Output is correct
10 Correct 53 ms 139712 KB Output is correct
11 Correct 50 ms 139600 KB Output is correct
12 Correct 56 ms 139600 KB Output is correct
13 Correct 52 ms 139604 KB Output is correct
14 Correct 50 ms 139596 KB Output is correct
15 Correct 52 ms 139600 KB Output is correct
16 Correct 51 ms 139604 KB Output is correct
17 Correct 53 ms 139604 KB Output is correct
18 Correct 50 ms 139604 KB Output is correct
19 Correct 50 ms 139604 KB Output is correct
20 Correct 55 ms 139604 KB Output is correct
21 Correct 50 ms 139584 KB Output is correct
22 Correct 55 ms 139652 KB Output is correct
23 Correct 48 ms 139696 KB Output is correct
24 Correct 53 ms 139600 KB Output is correct
25 Correct 132 ms 142672 KB Output is correct
26 Correct 133 ms 142676 KB Output is correct
27 Correct 146 ms 142672 KB Output is correct
28 Correct 152 ms 142672 KB Output is correct
29 Correct 128 ms 142676 KB Output is correct
30 Correct 126 ms 142680 KB Output is correct
31 Correct 59 ms 139968 KB Output is correct
32 Correct 63 ms 140116 KB Output is correct
33 Correct 57 ms 139964 KB Output is correct
34 Correct 58 ms 140100 KB Output is correct
35 Correct 134 ms 141908 KB Output is correct
36 Correct 134 ms 141908 KB Output is correct
37 Correct 150 ms 141904 KB Output is correct
38 Correct 144 ms 141844 KB Output is correct
39 Correct 129 ms 141652 KB Output is correct
40 Correct 125 ms 141800 KB Output is correct
41 Correct 58 ms 139860 KB Output is correct
42 Correct 63 ms 139860 KB Output is correct
43 Correct 137 ms 141660 KB Output is correct
44 Correct 136 ms 141652 KB Output is correct
45 Correct 150 ms 141668 KB Output is correct
46 Correct 148 ms 141740 KB Output is correct
47 Correct 130 ms 141652 KB Output is correct
48 Correct 125 ms 141636 KB Output is correct
49 Correct 61 ms 139856 KB Output is correct
50 Correct 60 ms 139856 KB Output is correct
51 Correct 259 ms 147280 KB Output is correct
52 Correct 263 ms 147284 KB Output is correct
53 Correct 306 ms 147380 KB Output is correct
54 Correct 295 ms 147280 KB Output is correct
55 Correct 259 ms 147452 KB Output is correct
56 Correct 248 ms 147284 KB Output is correct
57 Correct 94 ms 141136 KB Output is correct
58 Correct 85 ms 141140 KB Output is correct
59 Correct 90 ms 141076 KB Output is correct
60 Correct 85 ms 141040 KB Output is correct
61 Correct 268 ms 145096 KB Output is correct
62 Correct 271 ms 145200 KB Output is correct
63 Correct 307 ms 144976 KB Output is correct
64 Correct 316 ms 144976 KB Output is correct
65 Correct 250 ms 144980 KB Output is correct
66 Correct 246 ms 144976 KB Output is correct
67 Correct 96 ms 140568 KB Output is correct
68 Correct 87 ms 140624 KB Output is correct
69 Correct 269 ms 144920 KB Output is correct
70 Correct 299 ms 144924 KB Output is correct
71 Correct 301 ms 144996 KB Output is correct
72 Correct 310 ms 144976 KB Output is correct
73 Correct 243 ms 144464 KB Output is correct
74 Correct 250 ms 144660 KB Output is correct
75 Correct 89 ms 140628 KB Output is correct
76 Correct 95 ms 140624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 139792 KB Output is correct
2 Correct 52 ms 139760 KB Output is correct
3 Correct 53 ms 139852 KB Output is correct
4 Correct 51 ms 139600 KB Output is correct
5 Correct 51 ms 139600 KB Output is correct
6 Correct 52 ms 139700 KB Output is correct
7 Correct 49 ms 139612 KB Output is correct
8 Correct 54 ms 139680 KB Output is correct
9 Correct 52 ms 139752 KB Output is correct
10 Correct 53 ms 139712 KB Output is correct
11 Correct 50 ms 139600 KB Output is correct
12 Correct 56 ms 139600 KB Output is correct
13 Correct 52 ms 139604 KB Output is correct
14 Correct 50 ms 139596 KB Output is correct
15 Correct 52 ms 139600 KB Output is correct
16 Correct 51 ms 139604 KB Output is correct
17 Correct 53 ms 139604 KB Output is correct
18 Correct 50 ms 139604 KB Output is correct
19 Correct 50 ms 139604 KB Output is correct
20 Correct 55 ms 139604 KB Output is correct
21 Correct 50 ms 139584 KB Output is correct
22 Correct 55 ms 139652 KB Output is correct
23 Correct 48 ms 139696 KB Output is correct
24 Correct 53 ms 139600 KB Output is correct
25 Correct 51 ms 139604 KB Output is correct
26 Correct 51 ms 139604 KB Output is correct
27 Correct 51 ms 139604 KB Output is correct
28 Correct 52 ms 139860 KB Output is correct
29 Correct 50 ms 139600 KB Output is correct
30 Correct 50 ms 139604 KB Output is correct
31 Correct 51 ms 139600 KB Output is correct
32 Correct 51 ms 139856 KB Output is correct
33 Correct 51 ms 139656 KB Output is correct
34 Correct 52 ms 139780 KB Output is correct
35 Correct 51 ms 139600 KB Output is correct
36 Correct 52 ms 139600 KB Output is correct
37 Correct 54 ms 139640 KB Output is correct
38 Correct 55 ms 139604 KB Output is correct
39 Correct 51 ms 139604 KB Output is correct
40 Correct 51 ms 139604 KB Output is correct
41 Correct 51 ms 139604 KB Output is correct
42 Correct 51 ms 139816 KB Output is correct
43 Correct 52 ms 139604 KB Output is correct
44 Correct 54 ms 139604 KB Output is correct
45 Correct 53 ms 139600 KB Output is correct
46 Correct 52 ms 139604 KB Output is correct
47 Correct 51 ms 139600 KB Output is correct
48 Correct 50 ms 139760 KB Output is correct
49 Correct 51 ms 139600 KB Output is correct
50 Correct 52 ms 139600 KB Output is correct
51 Correct 132 ms 142672 KB Output is correct
52 Correct 133 ms 142676 KB Output is correct
53 Correct 146 ms 142672 KB Output is correct
54 Correct 152 ms 142672 KB Output is correct
55 Correct 128 ms 142676 KB Output is correct
56 Correct 126 ms 142680 KB Output is correct
57 Correct 59 ms 139968 KB Output is correct
58 Correct 63 ms 140116 KB Output is correct
59 Correct 57 ms 139964 KB Output is correct
60 Correct 58 ms 140100 KB Output is correct
61 Correct 134 ms 141908 KB Output is correct
62 Correct 134 ms 141908 KB Output is correct
63 Correct 150 ms 141904 KB Output is correct
64 Correct 144 ms 141844 KB Output is correct
65 Correct 129 ms 141652 KB Output is correct
66 Correct 125 ms 141800 KB Output is correct
67 Correct 58 ms 139860 KB Output is correct
68 Correct 63 ms 139860 KB Output is correct
69 Correct 137 ms 141660 KB Output is correct
70 Correct 136 ms 141652 KB Output is correct
71 Correct 150 ms 141668 KB Output is correct
72 Correct 148 ms 141740 KB Output is correct
73 Correct 130 ms 141652 KB Output is correct
74 Correct 125 ms 141636 KB Output is correct
75 Correct 61 ms 139856 KB Output is correct
76 Correct 60 ms 139856 KB Output is correct
77 Correct 259 ms 147280 KB Output is correct
78 Correct 263 ms 147284 KB Output is correct
79 Correct 306 ms 147380 KB Output is correct
80 Correct 295 ms 147280 KB Output is correct
81 Correct 259 ms 147452 KB Output is correct
82 Correct 248 ms 147284 KB Output is correct
83 Correct 94 ms 141136 KB Output is correct
84 Correct 85 ms 141140 KB Output is correct
85 Correct 90 ms 141076 KB Output is correct
86 Correct 85 ms 141040 KB Output is correct
87 Correct 268 ms 145096 KB Output is correct
88 Correct 271 ms 145200 KB Output is correct
89 Correct 307 ms 144976 KB Output is correct
90 Correct 316 ms 144976 KB Output is correct
91 Correct 250 ms 144980 KB Output is correct
92 Correct 246 ms 144976 KB Output is correct
93 Correct 96 ms 140568 KB Output is correct
94 Correct 87 ms 140624 KB Output is correct
95 Correct 269 ms 144920 KB Output is correct
96 Correct 299 ms 144924 KB Output is correct
97 Correct 301 ms 144996 KB Output is correct
98 Correct 310 ms 144976 KB Output is correct
99 Correct 243 ms 144464 KB Output is correct
100 Correct 250 ms 144660 KB Output is correct
101 Correct 89 ms 140628 KB Output is correct
102 Correct 95 ms 140624 KB Output is correct
103 Correct 314 ms 147848 KB Output is correct
104 Correct 320 ms 147796 KB Output is correct
105 Correct 473 ms 150864 KB Output is correct
106 Correct 449 ms 150876 KB Output is correct
107 Correct 321 ms 150360 KB Output is correct
108 Correct 314 ms 150360 KB Output is correct
109 Correct 104 ms 141828 KB Output is correct
110 Correct 100 ms 141908 KB Output is correct
111 Correct 101 ms 141844 KB Output is correct
112 Correct 105 ms 141908 KB Output is correct
113 Correct 317 ms 148044 KB Output is correct
114 Correct 320 ms 148052 KB Output is correct
115 Correct 429 ms 148656 KB Output is correct
116 Correct 428 ms 148560 KB Output is correct
117 Correct 287 ms 148052 KB Output is correct
118 Correct 297 ms 148052 KB Output is correct
119 Correct 104 ms 141416 KB Output is correct
120 Correct 102 ms 141328 KB Output is correct
121 Correct 327 ms 147724 KB Output is correct
122 Correct 325 ms 147792 KB Output is correct
123 Correct 420 ms 148384 KB Output is correct
124 Correct 421 ms 148308 KB Output is correct
125 Correct 292 ms 147916 KB Output is correct
126 Correct 284 ms 147560 KB Output is correct
127 Correct 109 ms 141392 KB Output is correct
128 Correct 102 ms 141392 KB Output is correct