답안 #747083

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747083 2023-05-23T15:25:05 Z MilosMilutinovic Vinjete (COI22_vinjete) C++14
100 / 100
697 ms 152852 KB
/**
 *    author:  wxhtzdy
 *    created: 20.12.2022 14:09:07
**/
#include <bits/stdc++.h>

using namespace std;

const int M = 8e6;

int root, tsz, ls[M], rs[M], mn[M], cnt[M], add[M];

int make_node(int l, int r) {
  int node = ++tsz;
  cnt[node] = max(0, r - l + 1);
  if (l > r) {
    mn[node] = 1e6;
  }
  return node;
}

void push(int x, int l, int r) {
  if (add[x] == 0) {
    return;
  }
  int mid = l + r >> 1;
  if (!ls[x]) {
    ls[x] = make_node(l, mid);
  }
  if (!rs[x]) {
    rs[x] = make_node(mid + 1, r);
  }
  mn[ls[x]] += add[x];
  mn[rs[x]] += add[x];
  add[ls[x]] += add[x];
  add[rs[x]] += add[x];
  add[x] = 0;
}

void pull(int x) {
  mn[x] = min(mn[ls[x]], mn[rs[x]]);
  cnt[x] = (mn[ls[x]] == mn[x] ? cnt[ls[x]] : 0) + (mn[rs[x]] == mn[x] ? cnt[rs[x]] : 0);
}

void modify(int x, int l, int r, int ll, int rr, int v) {
  assert(x > 0);
  if (l > r || l > rr || r < ll) {
    return;
  }
  if (ll <= l && r <= rr) {
    mn[x] += v;
    add[x] += v;
    push(x, l, r);
    return;
  }
  push(x, l, r);
  int mid = l + r >> 1;
  if (!ls[x]) {
    ls[x] = make_node(l, mid);
  }
  modify(ls[x], l, mid, ll, rr, v);
  if (!rs[x]) {
    rs[x] = make_node(mid + 1, r);
  }
  modify(rs[x], mid + 1, r, ll, rr, v);
  pull(x);
}


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n, m;
  cin >> n >> m;
  vector<vector<array<int, 3>>> g(n);
  for (int i = 1; i < n; i++) {
    int x, y, l, r;
    cin >> x >> y >> l >> r;
    --x; --y;
    g[x].push_back({y, l, r});
    g[y].push_back({x, l, r});
  }
  root = make_node(1, m);
  vector<int> ans(n);
  function<void(int, int)> Dfs = [&](int v, int pv) {
    ans[v] = (mn[root] == 0 ? m - cnt[root] : m);
    for (auto p : g[v]) {
      int u = p[0];
      int l = p[1];
      int r = p[2];
      if (u == pv) {
        continue;
      }
      modify(root, 1, m, l, r, +1);
      Dfs(u, v);
      modify(root, 1, m, l, r, -1);
    }
  };
  Dfs(0, 0);
  for (int i = 1; i < n; i++) {
    cout << ans[i] << '\n';
  }                                                               
  return 0;
}

Compilation message

Main.cpp: In function 'void push(int, int, int)':
Main.cpp:26:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   26 |   int mid = l + r >> 1;
      |             ~~^~~
Main.cpp: In function 'void modify(int, int, int, int, int, int)':
Main.cpp:57:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   57 |   int mid = l + r >> 1;
      |             ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 388 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 396 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 388 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 396 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 3 ms 500 KB Output is correct
27 Correct 5 ms 2644 KB Output is correct
28 Correct 6 ms 2556 KB Output is correct
29 Correct 3 ms 1236 KB Output is correct
30 Correct 4 ms 1332 KB Output is correct
31 Correct 4 ms 2644 KB Output is correct
32 Correct 4 ms 2644 KB Output is correct
33 Correct 4 ms 2644 KB Output is correct
34 Correct 5 ms 2568 KB Output is correct
35 Correct 4 ms 468 KB Output is correct
36 Correct 3 ms 388 KB Output is correct
37 Correct 5 ms 2552 KB Output is correct
38 Correct 6 ms 2516 KB Output is correct
39 Correct 2 ms 1268 KB Output is correct
40 Correct 3 ms 1236 KB Output is correct
41 Correct 4 ms 2516 KB Output is correct
42 Correct 4 ms 2516 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 3 ms 468 KB Output is correct
45 Correct 6 ms 2516 KB Output is correct
46 Correct 5 ms 2516 KB Output is correct
47 Correct 3 ms 1236 KB Output is correct
48 Correct 3 ms 1236 KB Output is correct
49 Correct 5 ms 2516 KB Output is correct
50 Correct 5 ms 2492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 388 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 396 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 63 ms 7244 KB Output is correct
26 Correct 61 ms 7244 KB Output is correct
27 Correct 81 ms 9840 KB Output is correct
28 Correct 82 ms 10032 KB Output is correct
29 Correct 47 ms 9944 KB Output is correct
30 Correct 46 ms 9932 KB Output is correct
31 Correct 6 ms 2388 KB Output is correct
32 Correct 6 ms 2388 KB Output is correct
33 Correct 7 ms 2516 KB Output is correct
34 Correct 6 ms 2388 KB Output is correct
35 Correct 65 ms 4236 KB Output is correct
36 Correct 77 ms 4480 KB Output is correct
37 Correct 96 ms 7016 KB Output is correct
38 Correct 82 ms 7020 KB Output is correct
39 Correct 50 ms 6472 KB Output is correct
40 Correct 52 ms 6480 KB Output is correct
41 Correct 8 ms 2060 KB Output is correct
42 Correct 7 ms 2140 KB Output is correct
43 Correct 62 ms 4052 KB Output is correct
44 Correct 64 ms 4028 KB Output is correct
45 Correct 76 ms 6604 KB Output is correct
46 Correct 82 ms 6400 KB Output is correct
47 Correct 76 ms 6704 KB Output is correct
48 Correct 46 ms 6616 KB Output is correct
49 Correct 7 ms 2004 KB Output is correct
50 Correct 6 ms 2036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 388 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 396 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 63 ms 7244 KB Output is correct
26 Correct 61 ms 7244 KB Output is correct
27 Correct 81 ms 9840 KB Output is correct
28 Correct 82 ms 10032 KB Output is correct
29 Correct 47 ms 9944 KB Output is correct
30 Correct 46 ms 9932 KB Output is correct
31 Correct 6 ms 2388 KB Output is correct
32 Correct 6 ms 2388 KB Output is correct
33 Correct 7 ms 2516 KB Output is correct
34 Correct 6 ms 2388 KB Output is correct
35 Correct 65 ms 4236 KB Output is correct
36 Correct 77 ms 4480 KB Output is correct
37 Correct 96 ms 7016 KB Output is correct
38 Correct 82 ms 7020 KB Output is correct
39 Correct 50 ms 6472 KB Output is correct
40 Correct 52 ms 6480 KB Output is correct
41 Correct 8 ms 2060 KB Output is correct
42 Correct 7 ms 2140 KB Output is correct
43 Correct 62 ms 4052 KB Output is correct
44 Correct 64 ms 4028 KB Output is correct
45 Correct 76 ms 6604 KB Output is correct
46 Correct 82 ms 6400 KB Output is correct
47 Correct 76 ms 6704 KB Output is correct
48 Correct 46 ms 6616 KB Output is correct
49 Correct 7 ms 2004 KB Output is correct
50 Correct 6 ms 2036 KB Output is correct
51 Correct 164 ms 18344 KB Output is correct
52 Correct 159 ms 18324 KB Output is correct
53 Correct 289 ms 24860 KB Output is correct
54 Correct 245 ms 24808 KB Output is correct
55 Correct 141 ms 24112 KB Output is correct
56 Correct 129 ms 24388 KB Output is correct
57 Correct 22 ms 8012 KB Output is correct
58 Correct 24 ms 7996 KB Output is correct
59 Correct 23 ms 7944 KB Output is correct
60 Correct 21 ms 7948 KB Output is correct
61 Correct 166 ms 10600 KB Output is correct
62 Correct 162 ms 11052 KB Output is correct
63 Correct 266 ms 17140 KB Output is correct
64 Correct 225 ms 17424 KB Output is correct
65 Correct 170 ms 17260 KB Output is correct
66 Correct 144 ms 16212 KB Output is correct
67 Correct 23 ms 6476 KB Output is correct
68 Correct 21 ms 6472 KB Output is correct
69 Correct 177 ms 9936 KB Output is correct
70 Correct 180 ms 9904 KB Output is correct
71 Correct 238 ms 16544 KB Output is correct
72 Correct 233 ms 16668 KB Output is correct
73 Correct 136 ms 16032 KB Output is correct
74 Correct 156 ms 16060 KB Output is correct
75 Correct 25 ms 6220 KB Output is correct
76 Correct 25 ms 6224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 388 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 396 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 3 ms 500 KB Output is correct
27 Correct 5 ms 2644 KB Output is correct
28 Correct 6 ms 2556 KB Output is correct
29 Correct 3 ms 1236 KB Output is correct
30 Correct 4 ms 1332 KB Output is correct
31 Correct 4 ms 2644 KB Output is correct
32 Correct 4 ms 2644 KB Output is correct
33 Correct 4 ms 2644 KB Output is correct
34 Correct 5 ms 2568 KB Output is correct
35 Correct 4 ms 468 KB Output is correct
36 Correct 3 ms 388 KB Output is correct
37 Correct 5 ms 2552 KB Output is correct
38 Correct 6 ms 2516 KB Output is correct
39 Correct 2 ms 1268 KB Output is correct
40 Correct 3 ms 1236 KB Output is correct
41 Correct 4 ms 2516 KB Output is correct
42 Correct 4 ms 2516 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 3 ms 468 KB Output is correct
45 Correct 6 ms 2516 KB Output is correct
46 Correct 5 ms 2516 KB Output is correct
47 Correct 3 ms 1236 KB Output is correct
48 Correct 3 ms 1236 KB Output is correct
49 Correct 5 ms 2516 KB Output is correct
50 Correct 5 ms 2492 KB Output is correct
51 Correct 63 ms 7244 KB Output is correct
52 Correct 61 ms 7244 KB Output is correct
53 Correct 81 ms 9840 KB Output is correct
54 Correct 82 ms 10032 KB Output is correct
55 Correct 47 ms 9944 KB Output is correct
56 Correct 46 ms 9932 KB Output is correct
57 Correct 6 ms 2388 KB Output is correct
58 Correct 6 ms 2388 KB Output is correct
59 Correct 7 ms 2516 KB Output is correct
60 Correct 6 ms 2388 KB Output is correct
61 Correct 65 ms 4236 KB Output is correct
62 Correct 77 ms 4480 KB Output is correct
63 Correct 96 ms 7016 KB Output is correct
64 Correct 82 ms 7020 KB Output is correct
65 Correct 50 ms 6472 KB Output is correct
66 Correct 52 ms 6480 KB Output is correct
67 Correct 8 ms 2060 KB Output is correct
68 Correct 7 ms 2140 KB Output is correct
69 Correct 62 ms 4052 KB Output is correct
70 Correct 64 ms 4028 KB Output is correct
71 Correct 76 ms 6604 KB Output is correct
72 Correct 82 ms 6400 KB Output is correct
73 Correct 76 ms 6704 KB Output is correct
74 Correct 46 ms 6616 KB Output is correct
75 Correct 7 ms 2004 KB Output is correct
76 Correct 6 ms 2036 KB Output is correct
77 Correct 164 ms 18344 KB Output is correct
78 Correct 159 ms 18324 KB Output is correct
79 Correct 289 ms 24860 KB Output is correct
80 Correct 245 ms 24808 KB Output is correct
81 Correct 141 ms 24112 KB Output is correct
82 Correct 129 ms 24388 KB Output is correct
83 Correct 22 ms 8012 KB Output is correct
84 Correct 24 ms 7996 KB Output is correct
85 Correct 23 ms 7944 KB Output is correct
86 Correct 21 ms 7948 KB Output is correct
87 Correct 166 ms 10600 KB Output is correct
88 Correct 162 ms 11052 KB Output is correct
89 Correct 266 ms 17140 KB Output is correct
90 Correct 225 ms 17424 KB Output is correct
91 Correct 170 ms 17260 KB Output is correct
92 Correct 144 ms 16212 KB Output is correct
93 Correct 23 ms 6476 KB Output is correct
94 Correct 21 ms 6472 KB Output is correct
95 Correct 177 ms 9936 KB Output is correct
96 Correct 180 ms 9904 KB Output is correct
97 Correct 238 ms 16544 KB Output is correct
98 Correct 233 ms 16668 KB Output is correct
99 Correct 136 ms 16032 KB Output is correct
100 Correct 156 ms 16060 KB Output is correct
101 Correct 25 ms 6220 KB Output is correct
102 Correct 25 ms 6224 KB Output is correct
103 Correct 256 ms 19088 KB Output is correct
104 Correct 248 ms 19176 KB Output is correct
105 Correct 697 ms 152852 KB Output is correct
106 Correct 673 ms 151920 KB Output is correct
107 Correct 280 ms 75460 KB Output is correct
108 Correct 269 ms 75764 KB Output is correct
109 Correct 65 ms 36448 KB Output is correct
110 Correct 63 ms 36460 KB Output is correct
111 Correct 61 ms 36372 KB Output is correct
112 Correct 63 ms 36436 KB Output is correct
113 Correct 276 ms 12088 KB Output is correct
114 Correct 254 ms 11852 KB Output is correct
115 Correct 579 ms 145508 KB Output is correct
116 Correct 568 ms 145732 KB Output is correct
117 Correct 310 ms 68332 KB Output is correct
118 Correct 248 ms 67432 KB Output is correct
119 Correct 84 ms 35116 KB Output is correct
120 Correct 65 ms 35012 KB Output is correct
121 Correct 305 ms 10680 KB Output is correct
122 Correct 299 ms 10644 KB Output is correct
123 Correct 599 ms 141808 KB Output is correct
124 Correct 548 ms 141592 KB Output is correct
125 Correct 250 ms 64068 KB Output is correct
126 Correct 274 ms 66752 KB Output is correct
127 Correct 83 ms 34756 KB Output is correct
128 Correct 87 ms 34744 KB Output is correct