Submission #881009

# Submission time Handle Problem Language Result Execution time Memory
881009 2023-11-30T10:43:35 Z epicci23 Vinjete (COI22_vinjete) C++17
100 / 100
911 ms 441840 KB
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define endl '\n'
#define all(x) ((x).begin(),(x).end())
#define sz(x) ((int)(x).size())

const int N = 1e5 + 5;

struct Node{
  Node* lc;Node* rc;
  int lf,rg;
  int mini,cnt,lazy;
  Node(int ll,int rr){
    lc=rc=NULL;
    lazy=mini=0;
    lf=ll; rg=rr;
    cnt=rr-ll+1;
  }
};

Node* root;

void push(Node *rt){
  if(rt==NULL) return;
  int hl = rt->lf,hr = rt->rg;
  int hm = (hl+hr)/2;
  int u = rt->lazy;
  rt->mini+=u; rt->lazy=0;

  if(rt->lc==NULL)rt->lc=new Node(hl,hm);
  rt->lc->lazy+=u;
  
  if(rt->rc==NULL) rt->rc=new Node(hm+1,hr);
  rt->rc->lazy+=u;

  return;
}

void update(Node* rt,int l,int r,int gl,int gr,int u){
  push(rt);
  if(rt==NULL) return;
  if(r<gl || l>gr) return;
  if(l>=gl && r<=gr){
    rt->lazy+=u;
    push(rt); 
    return;
  }
  int mi = (l+r)/2;
  update(rt->lc,l,mi,gl,gr,u);
  update(rt->rc,mi+1,r,gl,gr,u);
  rt->mini=min(rt->lc->mini,rt->rc->mini);
  rt->cnt=0;
  if(rt->mini==rt->lc->mini) rt->cnt+=rt->lc->cnt;
  if(rt->mini==rt->rc->mini) rt->cnt+=rt->rc->cnt;
}

vector<array<int,3>> v[N];
int ans[N],n,m;

void dfs(int c,int p){
  push(root);

  if(root->mini==0) ans[c] = m - root->cnt;
  else ans[c]=m;

  for(auto x:v[c]){
    if(x[0]==p) continue;
    update(root,1,m,x[1],x[2],1);
    dfs(x[0],c);
    update(root,1,m,x[1],x[2],-1);
  }
}

void solve(){
  
  cin >> n >> m;
  root=new Node(1,m);
  for(int i=1;i<n;i++){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    v[a].pb({b,c,d});
    v[b].pb({a,c,d});
  }
  
  dfs(1,0);

  for(int i=2;i<=n;i++) cout << ans[i] << endl;
}

int32_t main(){
  ios::sync_with_stdio(0);cin.tie(0);
  int t=1;//cin >> t;
  while(t--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3164 KB Output is correct
2 Correct 2 ms 3164 KB Output is correct
3 Correct 2 ms 3164 KB Output is correct
4 Correct 3 ms 3420 KB Output is correct
5 Correct 2 ms 3292 KB Output is correct
6 Correct 2 ms 3164 KB Output is correct
7 Correct 1 ms 3024 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 3 ms 3164 KB Output is correct
12 Correct 3 ms 3572 KB Output is correct
13 Correct 2 ms 3164 KB Output is correct
14 Correct 2 ms 3164 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 2 ms 3044 KB Output is correct
18 Correct 2 ms 3032 KB Output is correct
19 Correct 2 ms 3164 KB Output is correct
20 Correct 2 ms 3164 KB Output is correct
21 Correct 2 ms 3164 KB Output is correct
22 Correct 2 ms 3236 KB Output is correct
23 Correct 1 ms 3020 KB Output is correct
24 Correct 1 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3164 KB Output is correct
2 Correct 2 ms 3164 KB Output is correct
3 Correct 2 ms 3164 KB Output is correct
4 Correct 3 ms 3420 KB Output is correct
5 Correct 2 ms 3292 KB Output is correct
6 Correct 2 ms 3164 KB Output is correct
7 Correct 1 ms 3024 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 3 ms 3164 KB Output is correct
12 Correct 3 ms 3572 KB Output is correct
13 Correct 2 ms 3164 KB Output is correct
14 Correct 2 ms 3164 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 2 ms 3044 KB Output is correct
18 Correct 2 ms 3032 KB Output is correct
19 Correct 2 ms 3164 KB Output is correct
20 Correct 2 ms 3164 KB Output is correct
21 Correct 2 ms 3164 KB Output is correct
22 Correct 2 ms 3236 KB Output is correct
23 Correct 1 ms 3020 KB Output is correct
24 Correct 1 ms 2908 KB Output is correct
25 Correct 4 ms 3164 KB Output is correct
26 Correct 3 ms 3212 KB Output is correct
27 Correct 9 ms 9820 KB Output is correct
28 Correct 8 ms 9820 KB Output is correct
29 Correct 5 ms 6748 KB Output is correct
30 Correct 5 ms 6748 KB Output is correct
31 Correct 8 ms 9768 KB Output is correct
32 Correct 8 ms 9816 KB Output is correct
33 Correct 11 ms 10072 KB Output is correct
34 Correct 11 ms 9816 KB Output is correct
35 Correct 3 ms 3156 KB Output is correct
36 Correct 3 ms 2904 KB Output is correct
37 Correct 11 ms 9764 KB Output is correct
38 Correct 8 ms 9820 KB Output is correct
39 Correct 5 ms 6748 KB Output is correct
40 Correct 5 ms 6748 KB Output is correct
41 Correct 8 ms 10072 KB Output is correct
42 Correct 8 ms 9820 KB Output is correct
43 Correct 4 ms 2908 KB Output is correct
44 Correct 4 ms 2908 KB Output is correct
45 Correct 8 ms 9728 KB Output is correct
46 Correct 9 ms 9816 KB Output is correct
47 Correct 5 ms 6744 KB Output is correct
48 Correct 5 ms 6748 KB Output is correct
49 Correct 8 ms 9820 KB Output is correct
50 Correct 8 ms 9820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3164 KB Output is correct
2 Correct 2 ms 3164 KB Output is correct
3 Correct 2 ms 3164 KB Output is correct
4 Correct 3 ms 3420 KB Output is correct
5 Correct 2 ms 3292 KB Output is correct
6 Correct 2 ms 3164 KB Output is correct
7 Correct 1 ms 3024 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 3 ms 3164 KB Output is correct
12 Correct 3 ms 3572 KB Output is correct
13 Correct 2 ms 3164 KB Output is correct
14 Correct 2 ms 3164 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 2 ms 3044 KB Output is correct
18 Correct 2 ms 3032 KB Output is correct
19 Correct 2 ms 3164 KB Output is correct
20 Correct 2 ms 3164 KB Output is correct
21 Correct 2 ms 3164 KB Output is correct
22 Correct 2 ms 3236 KB Output is correct
23 Correct 1 ms 3020 KB Output is correct
24 Correct 1 ms 2908 KB Output is correct
25 Correct 58 ms 8440 KB Output is correct
26 Correct 56 ms 8528 KB Output is correct
27 Correct 81 ms 15184 KB Output is correct
28 Correct 72 ms 15192 KB Output is correct
29 Correct 50 ms 15444 KB Output is correct
30 Correct 64 ms 15440 KB Output is correct
31 Correct 9 ms 7260 KB Output is correct
32 Correct 8 ms 7260 KB Output is correct
33 Correct 8 ms 7260 KB Output is correct
34 Correct 8 ms 7384 KB Output is correct
35 Correct 63 ms 6228 KB Output is correct
36 Correct 56 ms 6024 KB Output is correct
37 Correct 94 ms 12880 KB Output is correct
38 Correct 72 ms 13140 KB Output is correct
39 Correct 49 ms 12880 KB Output is correct
40 Correct 55 ms 12792 KB Output is correct
41 Correct 9 ms 7000 KB Output is correct
42 Correct 8 ms 7004 KB Output is correct
43 Correct 57 ms 5716 KB Output is correct
44 Correct 58 ms 5712 KB Output is correct
45 Correct 85 ms 12656 KB Output is correct
46 Correct 77 ms 12672 KB Output is correct
47 Correct 50 ms 12624 KB Output is correct
48 Correct 49 ms 12628 KB Output is correct
49 Correct 9 ms 7004 KB Output is correct
50 Correct 9 ms 7256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3164 KB Output is correct
2 Correct 2 ms 3164 KB Output is correct
3 Correct 2 ms 3164 KB Output is correct
4 Correct 3 ms 3420 KB Output is correct
5 Correct 2 ms 3292 KB Output is correct
6 Correct 2 ms 3164 KB Output is correct
7 Correct 1 ms 3024 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 3 ms 3164 KB Output is correct
12 Correct 3 ms 3572 KB Output is correct
13 Correct 2 ms 3164 KB Output is correct
14 Correct 2 ms 3164 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 2 ms 3044 KB Output is correct
18 Correct 2 ms 3032 KB Output is correct
19 Correct 2 ms 3164 KB Output is correct
20 Correct 2 ms 3164 KB Output is correct
21 Correct 2 ms 3164 KB Output is correct
22 Correct 2 ms 3236 KB Output is correct
23 Correct 1 ms 3020 KB Output is correct
24 Correct 1 ms 2908 KB Output is correct
25 Correct 58 ms 8440 KB Output is correct
26 Correct 56 ms 8528 KB Output is correct
27 Correct 81 ms 15184 KB Output is correct
28 Correct 72 ms 15192 KB Output is correct
29 Correct 50 ms 15444 KB Output is correct
30 Correct 64 ms 15440 KB Output is correct
31 Correct 9 ms 7260 KB Output is correct
32 Correct 8 ms 7260 KB Output is correct
33 Correct 8 ms 7260 KB Output is correct
34 Correct 8 ms 7384 KB Output is correct
35 Correct 63 ms 6228 KB Output is correct
36 Correct 56 ms 6024 KB Output is correct
37 Correct 94 ms 12880 KB Output is correct
38 Correct 72 ms 13140 KB Output is correct
39 Correct 49 ms 12880 KB Output is correct
40 Correct 55 ms 12792 KB Output is correct
41 Correct 9 ms 7000 KB Output is correct
42 Correct 8 ms 7004 KB Output is correct
43 Correct 57 ms 5716 KB Output is correct
44 Correct 58 ms 5712 KB Output is correct
45 Correct 85 ms 12656 KB Output is correct
46 Correct 77 ms 12672 KB Output is correct
47 Correct 50 ms 12624 KB Output is correct
48 Correct 49 ms 12628 KB Output is correct
49 Correct 9 ms 7004 KB Output is correct
50 Correct 9 ms 7256 KB Output is correct
51 Correct 168 ms 15968 KB Output is correct
52 Correct 147 ms 15956 KB Output is correct
53 Correct 243 ms 33628 KB Output is correct
54 Correct 225 ms 33620 KB Output is correct
55 Correct 193 ms 33364 KB Output is correct
56 Correct 150 ms 33396 KB Output is correct
57 Correct 42 ms 17236 KB Output is correct
58 Correct 37 ms 17388 KB Output is correct
59 Correct 30 ms 17288 KB Output is correct
60 Correct 31 ms 17244 KB Output is correct
61 Correct 145 ms 10016 KB Output is correct
62 Correct 146 ms 10320 KB Output is correct
63 Correct 223 ms 27224 KB Output is correct
64 Correct 239 ms 27368 KB Output is correct
65 Correct 146 ms 27668 KB Output is correct
66 Correct 146 ms 27412 KB Output is correct
67 Correct 36 ms 16120 KB Output is correct
68 Correct 39 ms 16232 KB Output is correct
69 Correct 150 ms 9260 KB Output is correct
70 Correct 150 ms 9296 KB Output is correct
71 Correct 235 ms 26880 KB Output is correct
72 Correct 244 ms 26912 KB Output is correct
73 Correct 153 ms 26548 KB Output is correct
74 Correct 150 ms 26452 KB Output is correct
75 Correct 36 ms 15904 KB Output is correct
76 Correct 39 ms 15852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3164 KB Output is correct
2 Correct 2 ms 3164 KB Output is correct
3 Correct 2 ms 3164 KB Output is correct
4 Correct 3 ms 3420 KB Output is correct
5 Correct 2 ms 3292 KB Output is correct
6 Correct 2 ms 3164 KB Output is correct
7 Correct 1 ms 3024 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 3 ms 3164 KB Output is correct
12 Correct 3 ms 3572 KB Output is correct
13 Correct 2 ms 3164 KB Output is correct
14 Correct 2 ms 3164 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 2 ms 3044 KB Output is correct
18 Correct 2 ms 3032 KB Output is correct
19 Correct 2 ms 3164 KB Output is correct
20 Correct 2 ms 3164 KB Output is correct
21 Correct 2 ms 3164 KB Output is correct
22 Correct 2 ms 3236 KB Output is correct
23 Correct 1 ms 3020 KB Output is correct
24 Correct 1 ms 2908 KB Output is correct
25 Correct 4 ms 3164 KB Output is correct
26 Correct 3 ms 3212 KB Output is correct
27 Correct 9 ms 9820 KB Output is correct
28 Correct 8 ms 9820 KB Output is correct
29 Correct 5 ms 6748 KB Output is correct
30 Correct 5 ms 6748 KB Output is correct
31 Correct 8 ms 9768 KB Output is correct
32 Correct 8 ms 9816 KB Output is correct
33 Correct 11 ms 10072 KB Output is correct
34 Correct 11 ms 9816 KB Output is correct
35 Correct 3 ms 3156 KB Output is correct
36 Correct 3 ms 2904 KB Output is correct
37 Correct 11 ms 9764 KB Output is correct
38 Correct 8 ms 9820 KB Output is correct
39 Correct 5 ms 6748 KB Output is correct
40 Correct 5 ms 6748 KB Output is correct
41 Correct 8 ms 10072 KB Output is correct
42 Correct 8 ms 9820 KB Output is correct
43 Correct 4 ms 2908 KB Output is correct
44 Correct 4 ms 2908 KB Output is correct
45 Correct 8 ms 9728 KB Output is correct
46 Correct 9 ms 9816 KB Output is correct
47 Correct 5 ms 6744 KB Output is correct
48 Correct 5 ms 6748 KB Output is correct
49 Correct 8 ms 9820 KB Output is correct
50 Correct 8 ms 9820 KB Output is correct
51 Correct 58 ms 8440 KB Output is correct
52 Correct 56 ms 8528 KB Output is correct
53 Correct 81 ms 15184 KB Output is correct
54 Correct 72 ms 15192 KB Output is correct
55 Correct 50 ms 15444 KB Output is correct
56 Correct 64 ms 15440 KB Output is correct
57 Correct 9 ms 7260 KB Output is correct
58 Correct 8 ms 7260 KB Output is correct
59 Correct 8 ms 7260 KB Output is correct
60 Correct 8 ms 7384 KB Output is correct
61 Correct 63 ms 6228 KB Output is correct
62 Correct 56 ms 6024 KB Output is correct
63 Correct 94 ms 12880 KB Output is correct
64 Correct 72 ms 13140 KB Output is correct
65 Correct 49 ms 12880 KB Output is correct
66 Correct 55 ms 12792 KB Output is correct
67 Correct 9 ms 7000 KB Output is correct
68 Correct 8 ms 7004 KB Output is correct
69 Correct 57 ms 5716 KB Output is correct
70 Correct 58 ms 5712 KB Output is correct
71 Correct 85 ms 12656 KB Output is correct
72 Correct 77 ms 12672 KB Output is correct
73 Correct 50 ms 12624 KB Output is correct
74 Correct 49 ms 12628 KB Output is correct
75 Correct 9 ms 7004 KB Output is correct
76 Correct 9 ms 7256 KB Output is correct
77 Correct 168 ms 15968 KB Output is correct
78 Correct 147 ms 15956 KB Output is correct
79 Correct 243 ms 33628 KB Output is correct
80 Correct 225 ms 33620 KB Output is correct
81 Correct 193 ms 33364 KB Output is correct
82 Correct 150 ms 33396 KB Output is correct
83 Correct 42 ms 17236 KB Output is correct
84 Correct 37 ms 17388 KB Output is correct
85 Correct 30 ms 17288 KB Output is correct
86 Correct 31 ms 17244 KB Output is correct
87 Correct 145 ms 10016 KB Output is correct
88 Correct 146 ms 10320 KB Output is correct
89 Correct 223 ms 27224 KB Output is correct
90 Correct 239 ms 27368 KB Output is correct
91 Correct 146 ms 27668 KB Output is correct
92 Correct 146 ms 27412 KB Output is correct
93 Correct 36 ms 16120 KB Output is correct
94 Correct 39 ms 16232 KB Output is correct
95 Correct 150 ms 9260 KB Output is correct
96 Correct 150 ms 9296 KB Output is correct
97 Correct 235 ms 26880 KB Output is correct
98 Correct 244 ms 26912 KB Output is correct
99 Correct 153 ms 26548 KB Output is correct
100 Correct 150 ms 26452 KB Output is correct
101 Correct 36 ms 15904 KB Output is correct
102 Correct 39 ms 15852 KB Output is correct
103 Correct 240 ms 16744 KB Output is correct
104 Correct 243 ms 16740 KB Output is correct
105 Correct 911 ms 441840 KB Output is correct
106 Correct 856 ms 441472 KB Output is correct
107 Correct 497 ms 269848 KB Output is correct
108 Correct 462 ms 270164 KB Output is correct
109 Correct 119 ms 109396 KB Output is correct
110 Correct 120 ms 109284 KB Output is correct
111 Correct 120 ms 109316 KB Output is correct
112 Correct 120 ms 109392 KB Output is correct
113 Correct 245 ms 11928 KB Output is correct
114 Correct 252 ms 11724 KB Output is correct
115 Correct 730 ms 435832 KB Output is correct
116 Correct 744 ms 436300 KB Output is correct
117 Correct 441 ms 263904 KB Output is correct
118 Correct 413 ms 263844 KB Output is correct
119 Correct 115 ms 108184 KB Output is correct
120 Correct 115 ms 108040 KB Output is correct
121 Correct 259 ms 10660 KB Output is correct
122 Correct 287 ms 10760 KB Output is correct
123 Correct 729 ms 435232 KB Output is correct
124 Correct 729 ms 435396 KB Output is correct
125 Correct 456 ms 263256 KB Output is correct
126 Correct 407 ms 262796 KB Output is correct
127 Correct 123 ms 107860 KB Output is correct
128 Correct 123 ms 107904 KB Output is correct