Submission #1019012

# Submission time Handle Problem Language Result Execution time Memory
1019012 2024-07-10T11:59:38 Z MarwenElarbi Vinjete (COI22_vinjete) C++17
69 / 100
360 ms 524288 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*30];
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 33 ms 84968 KB Output is correct
2 Correct 37 ms 84828 KB Output is correct
3 Correct 38 ms 84820 KB Output is correct
4 Correct 38 ms 84820 KB Output is correct
5 Correct 33 ms 85084 KB Output is correct
6 Correct 37 ms 84884 KB Output is correct
7 Correct 36 ms 84816 KB Output is correct
8 Correct 31 ms 84816 KB Output is correct
9 Correct 35 ms 84828 KB Output is correct
10 Correct 38 ms 84816 KB Output is correct
11 Correct 38 ms 84812 KB Output is correct
12 Correct 38 ms 84896 KB Output is correct
13 Correct 34 ms 84920 KB Output is correct
14 Correct 35 ms 84828 KB Output is correct
15 Correct 33 ms 84992 KB Output is correct
16 Correct 30 ms 84816 KB Output is correct
17 Correct 33 ms 84968 KB Output is correct
18 Correct 32 ms 84992 KB Output is correct
19 Correct 34 ms 84828 KB Output is correct
20 Correct 38 ms 84824 KB Output is correct
21 Correct 37 ms 84820 KB Output is correct
22 Correct 39 ms 84828 KB Output is correct
23 Correct 35 ms 84820 KB Output is correct
24 Correct 32 ms 84816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 84968 KB Output is correct
2 Correct 37 ms 84828 KB Output is correct
3 Correct 38 ms 84820 KB Output is correct
4 Correct 38 ms 84820 KB Output is correct
5 Correct 33 ms 85084 KB Output is correct
6 Correct 37 ms 84884 KB Output is correct
7 Correct 36 ms 84816 KB Output is correct
8 Correct 31 ms 84816 KB Output is correct
9 Correct 35 ms 84828 KB Output is correct
10 Correct 38 ms 84816 KB Output is correct
11 Correct 38 ms 84812 KB Output is correct
12 Correct 38 ms 84896 KB Output is correct
13 Correct 34 ms 84920 KB Output is correct
14 Correct 35 ms 84828 KB Output is correct
15 Correct 33 ms 84992 KB Output is correct
16 Correct 30 ms 84816 KB Output is correct
17 Correct 33 ms 84968 KB Output is correct
18 Correct 32 ms 84992 KB Output is correct
19 Correct 34 ms 84828 KB Output is correct
20 Correct 38 ms 84824 KB Output is correct
21 Correct 37 ms 84820 KB Output is correct
22 Correct 39 ms 84828 KB Output is correct
23 Correct 35 ms 84820 KB Output is correct
24 Correct 32 ms 84816 KB Output is correct
25 Correct 42 ms 85084 KB Output is correct
26 Correct 37 ms 85072 KB Output is correct
27 Correct 35 ms 85072 KB Output is correct
28 Correct 38 ms 85084 KB Output is correct
29 Correct 38 ms 84940 KB Output is correct
30 Correct 36 ms 85336 KB Output is correct
31 Correct 39 ms 85076 KB Output is correct
32 Correct 38 ms 85072 KB Output is correct
33 Correct 38 ms 85060 KB Output is correct
34 Correct 39 ms 85076 KB Output is correct
35 Correct 37 ms 84820 KB Output is correct
36 Correct 40 ms 84816 KB Output is correct
37 Correct 48 ms 84936 KB Output is correct
38 Correct 39 ms 84816 KB Output is correct
39 Correct 38 ms 84816 KB Output is correct
40 Correct 39 ms 84816 KB Output is correct
41 Correct 37 ms 84820 KB Output is correct
42 Correct 38 ms 84820 KB Output is correct
43 Correct 39 ms 84816 KB Output is correct
44 Correct 40 ms 84820 KB Output is correct
45 Correct 38 ms 84812 KB Output is correct
46 Correct 36 ms 85024 KB Output is correct
47 Correct 38 ms 84820 KB Output is correct
48 Correct 38 ms 85084 KB Output is correct
49 Correct 40 ms 84996 KB Output is correct
50 Correct 47 ms 84824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 84968 KB Output is correct
2 Correct 37 ms 84828 KB Output is correct
3 Correct 38 ms 84820 KB Output is correct
4 Correct 38 ms 84820 KB Output is correct
5 Correct 33 ms 85084 KB Output is correct
6 Correct 37 ms 84884 KB Output is correct
7 Correct 36 ms 84816 KB Output is correct
8 Correct 31 ms 84816 KB Output is correct
9 Correct 35 ms 84828 KB Output is correct
10 Correct 38 ms 84816 KB Output is correct
11 Correct 38 ms 84812 KB Output is correct
12 Correct 38 ms 84896 KB Output is correct
13 Correct 34 ms 84920 KB Output is correct
14 Correct 35 ms 84828 KB Output is correct
15 Correct 33 ms 84992 KB Output is correct
16 Correct 30 ms 84816 KB Output is correct
17 Correct 33 ms 84968 KB Output is correct
18 Correct 32 ms 84992 KB Output is correct
19 Correct 34 ms 84828 KB Output is correct
20 Correct 38 ms 84824 KB Output is correct
21 Correct 37 ms 84820 KB Output is correct
22 Correct 39 ms 84828 KB Output is correct
23 Correct 35 ms 84820 KB Output is correct
24 Correct 32 ms 84816 KB Output is correct
25 Correct 131 ms 88680 KB Output is correct
26 Correct 127 ms 88908 KB Output is correct
27 Correct 137 ms 88680 KB Output is correct
28 Correct 140 ms 88888 KB Output is correct
29 Correct 119 ms 88708 KB Output is correct
30 Correct 118 ms 88656 KB Output is correct
31 Correct 46 ms 85332 KB Output is correct
32 Correct 46 ms 85328 KB Output is correct
33 Correct 45 ms 85328 KB Output is correct
34 Correct 42 ms 85464 KB Output is correct
35 Correct 124 ms 87892 KB Output is correct
36 Correct 128 ms 87892 KB Output is correct
37 Correct 141 ms 87788 KB Output is correct
38 Correct 136 ms 87888 KB Output is correct
39 Correct 147 ms 87892 KB Output is correct
40 Correct 118 ms 87768 KB Output is correct
41 Correct 46 ms 85328 KB Output is correct
42 Correct 49 ms 85340 KB Output is correct
43 Correct 128 ms 87644 KB Output is correct
44 Correct 137 ms 87640 KB Output is correct
45 Correct 142 ms 87744 KB Output is correct
46 Correct 128 ms 87888 KB Output is correct
47 Correct 108 ms 87700 KB Output is correct
48 Correct 109 ms 87640 KB Output is correct
49 Correct 47 ms 85332 KB Output is correct
50 Correct 47 ms 85076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 84968 KB Output is correct
2 Correct 37 ms 84828 KB Output is correct
3 Correct 38 ms 84820 KB Output is correct
4 Correct 38 ms 84820 KB Output is correct
5 Correct 33 ms 85084 KB Output is correct
6 Correct 37 ms 84884 KB Output is correct
7 Correct 36 ms 84816 KB Output is correct
8 Correct 31 ms 84816 KB Output is correct
9 Correct 35 ms 84828 KB Output is correct
10 Correct 38 ms 84816 KB Output is correct
11 Correct 38 ms 84812 KB Output is correct
12 Correct 38 ms 84896 KB Output is correct
13 Correct 34 ms 84920 KB Output is correct
14 Correct 35 ms 84828 KB Output is correct
15 Correct 33 ms 84992 KB Output is correct
16 Correct 30 ms 84816 KB Output is correct
17 Correct 33 ms 84968 KB Output is correct
18 Correct 32 ms 84992 KB Output is correct
19 Correct 34 ms 84828 KB Output is correct
20 Correct 38 ms 84824 KB Output is correct
21 Correct 37 ms 84820 KB Output is correct
22 Correct 39 ms 84828 KB Output is correct
23 Correct 35 ms 84820 KB Output is correct
24 Correct 32 ms 84816 KB Output is correct
25 Correct 131 ms 88680 KB Output is correct
26 Correct 127 ms 88908 KB Output is correct
27 Correct 137 ms 88680 KB Output is correct
28 Correct 140 ms 88888 KB Output is correct
29 Correct 119 ms 88708 KB Output is correct
30 Correct 118 ms 88656 KB Output is correct
31 Correct 46 ms 85332 KB Output is correct
32 Correct 46 ms 85328 KB Output is correct
33 Correct 45 ms 85328 KB Output is correct
34 Correct 42 ms 85464 KB Output is correct
35 Correct 124 ms 87892 KB Output is correct
36 Correct 128 ms 87892 KB Output is correct
37 Correct 141 ms 87788 KB Output is correct
38 Correct 136 ms 87888 KB Output is correct
39 Correct 147 ms 87892 KB Output is correct
40 Correct 118 ms 87768 KB Output is correct
41 Correct 46 ms 85328 KB Output is correct
42 Correct 49 ms 85340 KB Output is correct
43 Correct 128 ms 87644 KB Output is correct
44 Correct 137 ms 87640 KB Output is correct
45 Correct 142 ms 87744 KB Output is correct
46 Correct 128 ms 87888 KB Output is correct
47 Correct 108 ms 87700 KB Output is correct
48 Correct 109 ms 87640 KB Output is correct
49 Correct 47 ms 85332 KB Output is correct
50 Correct 47 ms 85076 KB Output is correct
51 Correct 291 ms 94544 KB Output is correct
52 Correct 252 ms 94544 KB Output is correct
53 Correct 296 ms 94804 KB Output is correct
54 Correct 311 ms 94804 KB Output is correct
55 Correct 245 ms 94800 KB Output is correct
56 Correct 253 ms 94800 KB Output is correct
57 Correct 73 ms 86868 KB Output is correct
58 Correct 76 ms 86868 KB Output is correct
59 Correct 74 ms 86828 KB Output is correct
60 Correct 74 ms 86868 KB Output is correct
61 Correct 268 ms 92500 KB Output is correct
62 Correct 267 ms 92556 KB Output is correct
63 Correct 314 ms 92564 KB Output is correct
64 Correct 300 ms 92544 KB Output is correct
65 Correct 246 ms 92664 KB Output is correct
66 Correct 239 ms 92336 KB Output is correct
67 Correct 69 ms 86352 KB Output is correct
68 Correct 68 ms 86416 KB Output is correct
69 Correct 251 ms 92240 KB Output is correct
70 Correct 265 ms 92160 KB Output is correct
71 Correct 289 ms 92500 KB Output is correct
72 Correct 290 ms 92504 KB Output is correct
73 Correct 242 ms 92080 KB Output is correct
74 Correct 240 ms 91984 KB Output is correct
75 Correct 71 ms 86212 KB Output is correct
76 Correct 73 ms 86376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 84968 KB Output is correct
2 Correct 37 ms 84828 KB Output is correct
3 Correct 38 ms 84820 KB Output is correct
4 Correct 38 ms 84820 KB Output is correct
5 Correct 33 ms 85084 KB Output is correct
6 Correct 37 ms 84884 KB Output is correct
7 Correct 36 ms 84816 KB Output is correct
8 Correct 31 ms 84816 KB Output is correct
9 Correct 35 ms 84828 KB Output is correct
10 Correct 38 ms 84816 KB Output is correct
11 Correct 38 ms 84812 KB Output is correct
12 Correct 38 ms 84896 KB Output is correct
13 Correct 34 ms 84920 KB Output is correct
14 Correct 35 ms 84828 KB Output is correct
15 Correct 33 ms 84992 KB Output is correct
16 Correct 30 ms 84816 KB Output is correct
17 Correct 33 ms 84968 KB Output is correct
18 Correct 32 ms 84992 KB Output is correct
19 Correct 34 ms 84828 KB Output is correct
20 Correct 38 ms 84824 KB Output is correct
21 Correct 37 ms 84820 KB Output is correct
22 Correct 39 ms 84828 KB Output is correct
23 Correct 35 ms 84820 KB Output is correct
24 Correct 32 ms 84816 KB Output is correct
25 Correct 42 ms 85084 KB Output is correct
26 Correct 37 ms 85072 KB Output is correct
27 Correct 35 ms 85072 KB Output is correct
28 Correct 38 ms 85084 KB Output is correct
29 Correct 38 ms 84940 KB Output is correct
30 Correct 36 ms 85336 KB Output is correct
31 Correct 39 ms 85076 KB Output is correct
32 Correct 38 ms 85072 KB Output is correct
33 Correct 38 ms 85060 KB Output is correct
34 Correct 39 ms 85076 KB Output is correct
35 Correct 37 ms 84820 KB Output is correct
36 Correct 40 ms 84816 KB Output is correct
37 Correct 48 ms 84936 KB Output is correct
38 Correct 39 ms 84816 KB Output is correct
39 Correct 38 ms 84816 KB Output is correct
40 Correct 39 ms 84816 KB Output is correct
41 Correct 37 ms 84820 KB Output is correct
42 Correct 38 ms 84820 KB Output is correct
43 Correct 39 ms 84816 KB Output is correct
44 Correct 40 ms 84820 KB Output is correct
45 Correct 38 ms 84812 KB Output is correct
46 Correct 36 ms 85024 KB Output is correct
47 Correct 38 ms 84820 KB Output is correct
48 Correct 38 ms 85084 KB Output is correct
49 Correct 40 ms 84996 KB Output is correct
50 Correct 47 ms 84824 KB Output is correct
51 Correct 131 ms 88680 KB Output is correct
52 Correct 127 ms 88908 KB Output is correct
53 Correct 137 ms 88680 KB Output is correct
54 Correct 140 ms 88888 KB Output is correct
55 Correct 119 ms 88708 KB Output is correct
56 Correct 118 ms 88656 KB Output is correct
57 Correct 46 ms 85332 KB Output is correct
58 Correct 46 ms 85328 KB Output is correct
59 Correct 45 ms 85328 KB Output is correct
60 Correct 42 ms 85464 KB Output is correct
61 Correct 124 ms 87892 KB Output is correct
62 Correct 128 ms 87892 KB Output is correct
63 Correct 141 ms 87788 KB Output is correct
64 Correct 136 ms 87888 KB Output is correct
65 Correct 147 ms 87892 KB Output is correct
66 Correct 118 ms 87768 KB Output is correct
67 Correct 46 ms 85328 KB Output is correct
68 Correct 49 ms 85340 KB Output is correct
69 Correct 128 ms 87644 KB Output is correct
70 Correct 137 ms 87640 KB Output is correct
71 Correct 142 ms 87744 KB Output is correct
72 Correct 128 ms 87888 KB Output is correct
73 Correct 108 ms 87700 KB Output is correct
74 Correct 109 ms 87640 KB Output is correct
75 Correct 47 ms 85332 KB Output is correct
76 Correct 47 ms 85076 KB Output is correct
77 Correct 291 ms 94544 KB Output is correct
78 Correct 252 ms 94544 KB Output is correct
79 Correct 296 ms 94804 KB Output is correct
80 Correct 311 ms 94804 KB Output is correct
81 Correct 245 ms 94800 KB Output is correct
82 Correct 253 ms 94800 KB Output is correct
83 Correct 73 ms 86868 KB Output is correct
84 Correct 76 ms 86868 KB Output is correct
85 Correct 74 ms 86828 KB Output is correct
86 Correct 74 ms 86868 KB Output is correct
87 Correct 268 ms 92500 KB Output is correct
88 Correct 267 ms 92556 KB Output is correct
89 Correct 314 ms 92564 KB Output is correct
90 Correct 300 ms 92544 KB Output is correct
91 Correct 246 ms 92664 KB Output is correct
92 Correct 239 ms 92336 KB Output is correct
93 Correct 69 ms 86352 KB Output is correct
94 Correct 68 ms 86416 KB Output is correct
95 Correct 251 ms 92240 KB Output is correct
96 Correct 265 ms 92160 KB Output is correct
97 Correct 289 ms 92500 KB Output is correct
98 Correct 290 ms 92504 KB Output is correct
99 Correct 242 ms 92080 KB Output is correct
100 Correct 240 ms 91984 KB Output is correct
101 Correct 71 ms 86212 KB Output is correct
102 Correct 73 ms 86376 KB Output is correct
103 Correct 295 ms 95572 KB Output is correct
104 Correct 289 ms 95408 KB Output is correct
105 Runtime error 360 ms 524288 KB Execution killed with signal 9
106 Halted 0 ms 0 KB -