Submission #747067

# Submission time Handle Problem Language Result Execution time Memory
747067 2023-05-23T14:50:24 Z model_code Vinjete (COI22_vinjete) C++17
100 / 100
628 ms 312908 KB
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ll long long

using namespace std;

struct edge {
  int y;
  int a, b;
};

struct node {
  int val, sum;
  node *l, *r;

  node() {val = 0, sum = 0, l = r = NULL;}
};

const int OFF = (1 << 30);
const int MAXN = (1 << 17);
vector <node*> roots;

void update(int a, int b, int lo, int hi, node *x, node *y) {
  if (y->val != 0) {
    x->val = y->val;
    x->sum = x->val;
    return;
  }

  if (b <= lo || hi <= a) return;
  if (a <= lo && hi <= b) {
    x->val = (hi - lo);
    x->sum = x->val;
    return;
  }

  if (y->l == NULL) y->l = new node;
  if (y->r == NULL) y->r = new node;
  if (x->l == NULL) x->l = new node;
  if (x->r == NULL) x->r = new node;

  int mi = (lo + hi) / 2;

  if (mi <= a) {
    x->l = y->l;
  } else {
    update(a, b, lo, mi, x->l, y->l);
  }

  if (b <= mi) {
    x->r = y->r;
  } else {
    update(a, b, mi, hi, x->r, y->r);
  }

  x->sum = x->l->sum + x->r->sum;

  return;
}

int sol[MAXN];
vector <edge> ve[MAXN];

void dfs(int x, int par) {
  sol[x] = roots[x]->sum;

  for (auto tr : ve[x]) {
    if (tr.y == par) continue;
    update(tr.a - 1, tr.b, 0, OFF, roots[tr.y], roots[x]);
    dfs(tr.y, x);
  }

  return;
}

int main() {
  ios_base::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;
  REP(i, n - 1) {
    int x, y, a, b;
    cin >> x >> y >> a >> b;
    x--, y--;
    ve[x].push_back({y, a, b});
    ve[y].push_back({x, a, b});
  }

  REP(i, n) roots.push_back(new node);
  dfs(0, 0);
  for (int i = 1; i < n; ++i) cout << sol[i] << "\n";

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5076 KB Output is correct
2 Correct 7 ms 5076 KB Output is correct
3 Correct 5 ms 4948 KB Output is correct
4 Correct 5 ms 4948 KB Output is correct
5 Correct 8 ms 5460 KB Output is correct
6 Correct 7 ms 5460 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 3 ms 3540 KB Output is correct
9 Correct 7 ms 5204 KB Output is correct
10 Correct 5 ms 5224 KB Output is correct
11 Correct 5 ms 4948 KB Output is correct
12 Correct 5 ms 5076 KB Output is correct
13 Correct 7 ms 5332 KB Output is correct
14 Correct 10 ms 5332 KB Output is correct
15 Correct 2 ms 3540 KB Output is correct
16 Correct 2 ms 3540 KB Output is correct
17 Correct 5 ms 5204 KB Output is correct
18 Correct 5 ms 5204 KB Output is correct
19 Correct 6 ms 4948 KB Output is correct
20 Correct 4 ms 5076 KB Output is correct
21 Correct 5 ms 5352 KB Output is correct
22 Correct 7 ms 5332 KB Output is correct
23 Correct 3 ms 3540 KB Output is correct
24 Correct 3 ms 3540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5076 KB Output is correct
2 Correct 7 ms 5076 KB Output is correct
3 Correct 5 ms 4948 KB Output is correct
4 Correct 5 ms 4948 KB Output is correct
5 Correct 8 ms 5460 KB Output is correct
6 Correct 7 ms 5460 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 3 ms 3540 KB Output is correct
9 Correct 7 ms 5204 KB Output is correct
10 Correct 5 ms 5224 KB Output is correct
11 Correct 5 ms 4948 KB Output is correct
12 Correct 5 ms 5076 KB Output is correct
13 Correct 7 ms 5332 KB Output is correct
14 Correct 10 ms 5332 KB Output is correct
15 Correct 2 ms 3540 KB Output is correct
16 Correct 2 ms 3540 KB Output is correct
17 Correct 5 ms 5204 KB Output is correct
18 Correct 5 ms 5204 KB Output is correct
19 Correct 6 ms 4948 KB Output is correct
20 Correct 4 ms 5076 KB Output is correct
21 Correct 5 ms 5352 KB Output is correct
22 Correct 7 ms 5332 KB Output is correct
23 Correct 3 ms 3540 KB Output is correct
24 Correct 3 ms 3540 KB Output is correct
25 Correct 6 ms 5352 KB Output is correct
26 Correct 6 ms 4820 KB Output is correct
27 Correct 5 ms 3796 KB Output is correct
28 Correct 4 ms 3796 KB Output is correct
29 Correct 9 ms 6612 KB Output is correct
30 Correct 7 ms 6628 KB Output is correct
31 Correct 13 ms 8660 KB Output is correct
32 Correct 12 ms 8660 KB Output is correct
33 Correct 13 ms 8756 KB Output is correct
34 Correct 11 ms 8680 KB Output is correct
35 Correct 8 ms 5376 KB Output is correct
36 Correct 7 ms 5460 KB Output is correct
37 Correct 4 ms 4076 KB Output is correct
38 Correct 4 ms 4052 KB Output is correct
39 Correct 7 ms 6612 KB Output is correct
40 Correct 7 ms 6632 KB Output is correct
41 Correct 10 ms 8696 KB Output is correct
42 Correct 9 ms 8660 KB Output is correct
43 Correct 7 ms 6484 KB Output is correct
44 Correct 9 ms 6356 KB Output is correct
45 Correct 6 ms 4820 KB Output is correct
46 Correct 5 ms 4436 KB Output is correct
47 Correct 9 ms 6600 KB Output is correct
48 Correct 9 ms 6636 KB Output is correct
49 Correct 9 ms 8660 KB Output is correct
50 Correct 10 ms 8696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5076 KB Output is correct
2 Correct 7 ms 5076 KB Output is correct
3 Correct 5 ms 4948 KB Output is correct
4 Correct 5 ms 4948 KB Output is correct
5 Correct 8 ms 5460 KB Output is correct
6 Correct 7 ms 5460 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 3 ms 3540 KB Output is correct
9 Correct 7 ms 5204 KB Output is correct
10 Correct 5 ms 5224 KB Output is correct
11 Correct 5 ms 4948 KB Output is correct
12 Correct 5 ms 5076 KB Output is correct
13 Correct 7 ms 5332 KB Output is correct
14 Correct 10 ms 5332 KB Output is correct
15 Correct 2 ms 3540 KB Output is correct
16 Correct 2 ms 3540 KB Output is correct
17 Correct 5 ms 5204 KB Output is correct
18 Correct 5 ms 5204 KB Output is correct
19 Correct 6 ms 4948 KB Output is correct
20 Correct 4 ms 5076 KB Output is correct
21 Correct 5 ms 5352 KB Output is correct
22 Correct 7 ms 5332 KB Output is correct
23 Correct 3 ms 3540 KB Output is correct
24 Correct 3 ms 3540 KB Output is correct
25 Correct 95 ms 66060 KB Output is correct
26 Correct 95 ms 66140 KB Output is correct
27 Correct 77 ms 54036 KB Output is correct
28 Correct 82 ms 56372 KB Output is correct
29 Correct 140 ms 87272 KB Output is correct
30 Correct 167 ms 87132 KB Output is correct
31 Correct 20 ms 15108 KB Output is correct
32 Correct 20 ms 15124 KB Output is correct
33 Correct 20 ms 15164 KB Output is correct
34 Correct 21 ms 15212 KB Output is correct
35 Correct 105 ms 64648 KB Output is correct
36 Correct 127 ms 64984 KB Output is correct
37 Correct 132 ms 54740 KB Output is correct
38 Correct 127 ms 54028 KB Output is correct
39 Correct 208 ms 84688 KB Output is correct
40 Correct 163 ms 84652 KB Output is correct
41 Correct 20 ms 14924 KB Output is correct
42 Correct 21 ms 14884 KB Output is correct
43 Correct 171 ms 84504 KB Output is correct
44 Correct 137 ms 91384 KB Output is correct
45 Correct 112 ms 59044 KB Output is correct
46 Correct 107 ms 55836 KB Output is correct
47 Correct 193 ms 84944 KB Output is correct
48 Correct 146 ms 85188 KB Output is correct
49 Correct 27 ms 14852 KB Output is correct
50 Correct 23 ms 14896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5076 KB Output is correct
2 Correct 7 ms 5076 KB Output is correct
3 Correct 5 ms 4948 KB Output is correct
4 Correct 5 ms 4948 KB Output is correct
5 Correct 8 ms 5460 KB Output is correct
6 Correct 7 ms 5460 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 3 ms 3540 KB Output is correct
9 Correct 7 ms 5204 KB Output is correct
10 Correct 5 ms 5224 KB Output is correct
11 Correct 5 ms 4948 KB Output is correct
12 Correct 5 ms 5076 KB Output is correct
13 Correct 7 ms 5332 KB Output is correct
14 Correct 10 ms 5332 KB Output is correct
15 Correct 2 ms 3540 KB Output is correct
16 Correct 2 ms 3540 KB Output is correct
17 Correct 5 ms 5204 KB Output is correct
18 Correct 5 ms 5204 KB Output is correct
19 Correct 6 ms 4948 KB Output is correct
20 Correct 4 ms 5076 KB Output is correct
21 Correct 5 ms 5352 KB Output is correct
22 Correct 7 ms 5332 KB Output is correct
23 Correct 3 ms 3540 KB Output is correct
24 Correct 3 ms 3540 KB Output is correct
25 Correct 95 ms 66060 KB Output is correct
26 Correct 95 ms 66140 KB Output is correct
27 Correct 77 ms 54036 KB Output is correct
28 Correct 82 ms 56372 KB Output is correct
29 Correct 140 ms 87272 KB Output is correct
30 Correct 167 ms 87132 KB Output is correct
31 Correct 20 ms 15108 KB Output is correct
32 Correct 20 ms 15124 KB Output is correct
33 Correct 20 ms 15164 KB Output is correct
34 Correct 21 ms 15212 KB Output is correct
35 Correct 105 ms 64648 KB Output is correct
36 Correct 127 ms 64984 KB Output is correct
37 Correct 132 ms 54740 KB Output is correct
38 Correct 127 ms 54028 KB Output is correct
39 Correct 208 ms 84688 KB Output is correct
40 Correct 163 ms 84652 KB Output is correct
41 Correct 20 ms 14924 KB Output is correct
42 Correct 21 ms 14884 KB Output is correct
43 Correct 171 ms 84504 KB Output is correct
44 Correct 137 ms 91384 KB Output is correct
45 Correct 112 ms 59044 KB Output is correct
46 Correct 107 ms 55836 KB Output is correct
47 Correct 193 ms 84944 KB Output is correct
48 Correct 146 ms 85188 KB Output is correct
49 Correct 27 ms 14852 KB Output is correct
50 Correct 23 ms 14896 KB Output is correct
51 Correct 308 ms 167832 KB Output is correct
52 Correct 296 ms 167824 KB Output is correct
53 Correct 195 ms 121296 KB Output is correct
54 Correct 184 ms 121012 KB Output is correct
55 Correct 456 ms 213076 KB Output is correct
56 Correct 348 ms 213404 KB Output is correct
57 Correct 93 ms 49268 KB Output is correct
58 Correct 71 ms 49176 KB Output is correct
59 Correct 70 ms 49164 KB Output is correct
60 Correct 70 ms 49128 KB Output is correct
61 Correct 292 ms 163512 KB Output is correct
62 Correct 309 ms 163712 KB Output is correct
63 Correct 223 ms 118744 KB Output is correct
64 Correct 262 ms 119104 KB Output is correct
65 Correct 519 ms 208984 KB Output is correct
66 Correct 392 ms 208000 KB Output is correct
67 Correct 81 ms 48188 KB Output is correct
68 Correct 100 ms 48160 KB Output is correct
69 Correct 304 ms 166000 KB Output is correct
70 Correct 416 ms 232204 KB Output is correct
71 Correct 269 ms 137660 KB Output is correct
72 Correct 298 ms 143800 KB Output is correct
73 Correct 426 ms 208144 KB Output is correct
74 Correct 491 ms 208168 KB Output is correct
75 Correct 79 ms 48200 KB Output is correct
76 Correct 79 ms 48152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5076 KB Output is correct
2 Correct 7 ms 5076 KB Output is correct
3 Correct 5 ms 4948 KB Output is correct
4 Correct 5 ms 4948 KB Output is correct
5 Correct 8 ms 5460 KB Output is correct
6 Correct 7 ms 5460 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 3 ms 3540 KB Output is correct
9 Correct 7 ms 5204 KB Output is correct
10 Correct 5 ms 5224 KB Output is correct
11 Correct 5 ms 4948 KB Output is correct
12 Correct 5 ms 5076 KB Output is correct
13 Correct 7 ms 5332 KB Output is correct
14 Correct 10 ms 5332 KB Output is correct
15 Correct 2 ms 3540 KB Output is correct
16 Correct 2 ms 3540 KB Output is correct
17 Correct 5 ms 5204 KB Output is correct
18 Correct 5 ms 5204 KB Output is correct
19 Correct 6 ms 4948 KB Output is correct
20 Correct 4 ms 5076 KB Output is correct
21 Correct 5 ms 5352 KB Output is correct
22 Correct 7 ms 5332 KB Output is correct
23 Correct 3 ms 3540 KB Output is correct
24 Correct 3 ms 3540 KB Output is correct
25 Correct 6 ms 5352 KB Output is correct
26 Correct 6 ms 4820 KB Output is correct
27 Correct 5 ms 3796 KB Output is correct
28 Correct 4 ms 3796 KB Output is correct
29 Correct 9 ms 6612 KB Output is correct
30 Correct 7 ms 6628 KB Output is correct
31 Correct 13 ms 8660 KB Output is correct
32 Correct 12 ms 8660 KB Output is correct
33 Correct 13 ms 8756 KB Output is correct
34 Correct 11 ms 8680 KB Output is correct
35 Correct 8 ms 5376 KB Output is correct
36 Correct 7 ms 5460 KB Output is correct
37 Correct 4 ms 4076 KB Output is correct
38 Correct 4 ms 4052 KB Output is correct
39 Correct 7 ms 6612 KB Output is correct
40 Correct 7 ms 6632 KB Output is correct
41 Correct 10 ms 8696 KB Output is correct
42 Correct 9 ms 8660 KB Output is correct
43 Correct 7 ms 6484 KB Output is correct
44 Correct 9 ms 6356 KB Output is correct
45 Correct 6 ms 4820 KB Output is correct
46 Correct 5 ms 4436 KB Output is correct
47 Correct 9 ms 6600 KB Output is correct
48 Correct 9 ms 6636 KB Output is correct
49 Correct 9 ms 8660 KB Output is correct
50 Correct 10 ms 8696 KB Output is correct
51 Correct 95 ms 66060 KB Output is correct
52 Correct 95 ms 66140 KB Output is correct
53 Correct 77 ms 54036 KB Output is correct
54 Correct 82 ms 56372 KB Output is correct
55 Correct 140 ms 87272 KB Output is correct
56 Correct 167 ms 87132 KB Output is correct
57 Correct 20 ms 15108 KB Output is correct
58 Correct 20 ms 15124 KB Output is correct
59 Correct 20 ms 15164 KB Output is correct
60 Correct 21 ms 15212 KB Output is correct
61 Correct 105 ms 64648 KB Output is correct
62 Correct 127 ms 64984 KB Output is correct
63 Correct 132 ms 54740 KB Output is correct
64 Correct 127 ms 54028 KB Output is correct
65 Correct 208 ms 84688 KB Output is correct
66 Correct 163 ms 84652 KB Output is correct
67 Correct 20 ms 14924 KB Output is correct
68 Correct 21 ms 14884 KB Output is correct
69 Correct 171 ms 84504 KB Output is correct
70 Correct 137 ms 91384 KB Output is correct
71 Correct 112 ms 59044 KB Output is correct
72 Correct 107 ms 55836 KB Output is correct
73 Correct 193 ms 84944 KB Output is correct
74 Correct 146 ms 85188 KB Output is correct
75 Correct 27 ms 14852 KB Output is correct
76 Correct 23 ms 14896 KB Output is correct
77 Correct 308 ms 167832 KB Output is correct
78 Correct 296 ms 167824 KB Output is correct
79 Correct 195 ms 121296 KB Output is correct
80 Correct 184 ms 121012 KB Output is correct
81 Correct 456 ms 213076 KB Output is correct
82 Correct 348 ms 213404 KB Output is correct
83 Correct 93 ms 49268 KB Output is correct
84 Correct 71 ms 49176 KB Output is correct
85 Correct 70 ms 49164 KB Output is correct
86 Correct 70 ms 49128 KB Output is correct
87 Correct 292 ms 163512 KB Output is correct
88 Correct 309 ms 163712 KB Output is correct
89 Correct 223 ms 118744 KB Output is correct
90 Correct 262 ms 119104 KB Output is correct
91 Correct 519 ms 208984 KB Output is correct
92 Correct 392 ms 208000 KB Output is correct
93 Correct 81 ms 48188 KB Output is correct
94 Correct 100 ms 48160 KB Output is correct
95 Correct 304 ms 166000 KB Output is correct
96 Correct 416 ms 232204 KB Output is correct
97 Correct 269 ms 137660 KB Output is correct
98 Correct 298 ms 143800 KB Output is correct
99 Correct 426 ms 208144 KB Output is correct
100 Correct 491 ms 208168 KB Output is correct
101 Correct 79 ms 48200 KB Output is correct
102 Correct 79 ms 48152 KB Output is correct
103 Correct 241 ms 152172 KB Output is correct
104 Correct 304 ms 152308 KB Output is correct
105 Correct 121 ms 46072 KB Output is correct
106 Correct 129 ms 45996 KB Output is correct
107 Correct 628 ms 292232 KB Output is correct
108 Correct 538 ms 291876 KB Output is correct
109 Correct 129 ms 94716 KB Output is correct
110 Correct 145 ms 94708 KB Output is correct
111 Correct 131 ms 94612 KB Output is correct
112 Correct 126 ms 94280 KB Output is correct
113 Correct 294 ms 149696 KB Output is correct
114 Correct 282 ms 151420 KB Output is correct
115 Correct 193 ms 42184 KB Output is correct
116 Correct 201 ms 42188 KB Output is correct
117 Correct 605 ms 287820 KB Output is correct
118 Correct 538 ms 286904 KB Output is correct
119 Correct 153 ms 93796 KB Output is correct
120 Correct 144 ms 93756 KB Output is correct
121 Correct 544 ms 308308 KB Output is correct
122 Correct 519 ms 312908 KB Output is correct
123 Correct 202 ms 63000 KB Output is correct
124 Correct 166 ms 47044 KB Output is correct
125 Correct 500 ms 283956 KB Output is correct
126 Correct 529 ms 283904 KB Output is correct
127 Correct 162 ms 93072 KB Output is correct
128 Correct 138 ms 93116 KB Output is correct