답안 #963897

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963897 2024-04-16T02:20:54 Z becaido Vinjete (COI22_vinjete) C++17
100 / 100
259 ms 27320 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

#define lpos pos*2
#define rpos pos*2+1

const int SIZE = 2e5 + 5;

int n, m, len;
int ans[SIZE];
vector<int> lis;
vector<tuple<int, int, int>> adj[SIZE];

struct Node {
    int mn, sum, lazy;
    Node operator + (const Node &o) const {
        Node re;
        re.mn = min(mn, o.mn);
        re.sum = (mn == re.mn ? sum : 0) + (o.mn == re.mn ? o.sum : 0);
        re.lazy = 0;
        return re;
    }
} node[SIZE << 2];

void build(int pos, int l, int r) {
    if (l == r) {
        node[pos].sum = lis[l] - lis[l - 1];
        return;
    }
    int mid = (l + r) / 2;
    build(lpos, l, mid);
    build(rpos, mid + 1, r);
    node[pos] = node[lpos] + node[rpos];
}
void push(int pos, int l, int r) {
    if (node[pos].lazy == 0) return;
    node[pos].mn += node[pos].lazy;
    if (l < r) {
        node[lpos].lazy += node[pos].lazy;
        node[rpos].lazy += node[pos].lazy;
    }
    node[pos].lazy = 0;
}
void pull(int pos, int l, int r) {
    int mid = (l + r) / 2;
    push(lpos, l, mid);
    push(rpos, mid + 1, r);
    node[pos] = node[lpos] + node[rpos];
}
void upd(int pos, int l, int r, int L, int R, int x) {
    if (l == L && r == R) {
        node[pos].lazy += x;
        push(pos, L, R);
        return;
    }
    int mid = (L + R) / 2;
    push(pos, L, R);
    if (r <= mid) upd(lpos, l, r, L, mid, x);
    else if (l > mid) upd(rpos, l, r, mid + 1, R, x);
    else {
        upd(lpos, l, mid, L, mid, x);
        upd(rpos, mid + 1, r, mid + 1, R, x);
    }
    pull(pos, L, R);
}

void dfs(int pos, int fa) {
    ans[pos] = len - (node[1].mn == 0 ? node[1].sum : 0);
    for (auto [np, l, r] : adj[pos]) if (np != fa) {
        l = lower_bound(lis.begin(), lis.end(), l) - lis.begin() + 1;
        r = lower_bound(lis.begin(), lis.end(), r + 1) - lis.begin();
        upd(1, l, r, 1, m, 1);
        dfs(np, pos);
        upd(1, l, r, 1, m, -1);
    }
}

void solve() {
    cin >> n >> m;
    FOR (i, 2, n) {
        int a, b, l, r;
        cin >> a >> b >> l >> r;
        adj[a].pb(b, l, r);
        adj[b].pb(a, l, r);
        lis.pb(l), lis.pb(r + 1);
    }
    sort(lis.begin(), lis.end());
    lis.erase(unique(lis.begin(), lis.end()), lis.end());
    m = lis.size() - 1;
    len = lis.back() - lis[0];
    build(1, 1, m);
    dfs(1, 1);
    FOR (i, 2, n) cout << ans[i] << '\n';
}

int main() {
    Waimai;
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5212 KB Output is correct
2 Correct 4 ms 5212 KB Output is correct
3 Correct 4 ms 5212 KB Output is correct
4 Correct 4 ms 5212 KB Output is correct
5 Correct 4 ms 5212 KB Output is correct
6 Correct 4 ms 5212 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 5 ms 5208 KB Output is correct
10 Correct 4 ms 5212 KB Output is correct
11 Correct 4 ms 5224 KB Output is correct
12 Correct 4 ms 5208 KB Output is correct
13 Correct 3 ms 5212 KB Output is correct
14 Correct 3 ms 5188 KB Output is correct
15 Correct 3 ms 4952 KB Output is correct
16 Correct 3 ms 5164 KB Output is correct
17 Correct 4 ms 5184 KB Output is correct
18 Correct 5 ms 5208 KB Output is correct
19 Correct 5 ms 5212 KB Output is correct
20 Correct 4 ms 5212 KB Output is correct
21 Correct 4 ms 5268 KB Output is correct
22 Correct 4 ms 5216 KB Output is correct
23 Correct 4 ms 4960 KB Output is correct
24 Correct 3 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5212 KB Output is correct
2 Correct 4 ms 5212 KB Output is correct
3 Correct 4 ms 5212 KB Output is correct
4 Correct 4 ms 5212 KB Output is correct
5 Correct 4 ms 5212 KB Output is correct
6 Correct 4 ms 5212 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 5 ms 5208 KB Output is correct
10 Correct 4 ms 5212 KB Output is correct
11 Correct 4 ms 5224 KB Output is correct
12 Correct 4 ms 5208 KB Output is correct
13 Correct 3 ms 5212 KB Output is correct
14 Correct 3 ms 5188 KB Output is correct
15 Correct 3 ms 4952 KB Output is correct
16 Correct 3 ms 5164 KB Output is correct
17 Correct 4 ms 5184 KB Output is correct
18 Correct 5 ms 5208 KB Output is correct
19 Correct 5 ms 5212 KB Output is correct
20 Correct 4 ms 5212 KB Output is correct
21 Correct 4 ms 5268 KB Output is correct
22 Correct 4 ms 5216 KB Output is correct
23 Correct 4 ms 4960 KB Output is correct
24 Correct 3 ms 4956 KB Output is correct
25 Correct 4 ms 5464 KB Output is correct
26 Correct 4 ms 5184 KB Output is correct
27 Correct 4 ms 5212 KB Output is correct
28 Correct 4 ms 5212 KB Output is correct
29 Correct 4 ms 5212 KB Output is correct
30 Correct 5 ms 5212 KB Output is correct
31 Correct 4 ms 5212 KB Output is correct
32 Correct 4 ms 5176 KB Output is correct
33 Correct 4 ms 5344 KB Output is correct
34 Correct 4 ms 5212 KB Output is correct
35 Correct 4 ms 5164 KB Output is correct
36 Correct 4 ms 5212 KB Output is correct
37 Correct 4 ms 5212 KB Output is correct
38 Correct 4 ms 5208 KB Output is correct
39 Correct 4 ms 5212 KB Output is correct
40 Correct 4 ms 5288 KB Output is correct
41 Correct 3 ms 5212 KB Output is correct
42 Correct 4 ms 5212 KB Output is correct
43 Correct 4 ms 5212 KB Output is correct
44 Correct 4 ms 5212 KB Output is correct
45 Correct 4 ms 5212 KB Output is correct
46 Correct 4 ms 5212 KB Output is correct
47 Correct 4 ms 5212 KB Output is correct
48 Correct 4 ms 5212 KB Output is correct
49 Correct 4 ms 5068 KB Output is correct
50 Correct 4 ms 5180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5212 KB Output is correct
2 Correct 4 ms 5212 KB Output is correct
3 Correct 4 ms 5212 KB Output is correct
4 Correct 4 ms 5212 KB Output is correct
5 Correct 4 ms 5212 KB Output is correct
6 Correct 4 ms 5212 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 5 ms 5208 KB Output is correct
10 Correct 4 ms 5212 KB Output is correct
11 Correct 4 ms 5224 KB Output is correct
12 Correct 4 ms 5208 KB Output is correct
13 Correct 3 ms 5212 KB Output is correct
14 Correct 3 ms 5188 KB Output is correct
15 Correct 3 ms 4952 KB Output is correct
16 Correct 3 ms 5164 KB Output is correct
17 Correct 4 ms 5184 KB Output is correct
18 Correct 5 ms 5208 KB Output is correct
19 Correct 5 ms 5212 KB Output is correct
20 Correct 4 ms 5212 KB Output is correct
21 Correct 4 ms 5268 KB Output is correct
22 Correct 4 ms 5216 KB Output is correct
23 Correct 4 ms 4960 KB Output is correct
24 Correct 3 ms 4956 KB Output is correct
25 Correct 43 ms 11040 KB Output is correct
26 Correct 47 ms 10808 KB Output is correct
27 Correct 74 ms 11720 KB Output is correct
28 Correct 71 ms 11852 KB Output is correct
29 Correct 48 ms 12484 KB Output is correct
30 Correct 49 ms 12508 KB Output is correct
31 Correct 7 ms 6232 KB Output is correct
32 Correct 9 ms 6076 KB Output is correct
33 Correct 7 ms 6236 KB Output is correct
34 Correct 7 ms 6196 KB Output is correct
35 Correct 40 ms 8316 KB Output is correct
36 Correct 40 ms 8468 KB Output is correct
37 Correct 71 ms 9204 KB Output is correct
38 Correct 81 ms 9548 KB Output is correct
39 Correct 46 ms 10076 KB Output is correct
40 Correct 52 ms 9944 KB Output is correct
41 Correct 9 ms 5988 KB Output is correct
42 Correct 7 ms 5980 KB Output is correct
43 Correct 42 ms 8144 KB Output is correct
44 Correct 51 ms 8228 KB Output is correct
45 Correct 73 ms 9048 KB Output is correct
46 Correct 68 ms 9008 KB Output is correct
47 Correct 49 ms 9764 KB Output is correct
48 Correct 58 ms 9756 KB Output is correct
49 Correct 7 ms 5944 KB Output is correct
50 Correct 7 ms 5720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5212 KB Output is correct
2 Correct 4 ms 5212 KB Output is correct
3 Correct 4 ms 5212 KB Output is correct
4 Correct 4 ms 5212 KB Output is correct
5 Correct 4 ms 5212 KB Output is correct
6 Correct 4 ms 5212 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 5 ms 5208 KB Output is correct
10 Correct 4 ms 5212 KB Output is correct
11 Correct 4 ms 5224 KB Output is correct
12 Correct 4 ms 5208 KB Output is correct
13 Correct 3 ms 5212 KB Output is correct
14 Correct 3 ms 5188 KB Output is correct
15 Correct 3 ms 4952 KB Output is correct
16 Correct 3 ms 5164 KB Output is correct
17 Correct 4 ms 5184 KB Output is correct
18 Correct 5 ms 5208 KB Output is correct
19 Correct 5 ms 5212 KB Output is correct
20 Correct 4 ms 5212 KB Output is correct
21 Correct 4 ms 5268 KB Output is correct
22 Correct 4 ms 5216 KB Output is correct
23 Correct 4 ms 4960 KB Output is correct
24 Correct 3 ms 4956 KB Output is correct
25 Correct 43 ms 11040 KB Output is correct
26 Correct 47 ms 10808 KB Output is correct
27 Correct 74 ms 11720 KB Output is correct
28 Correct 71 ms 11852 KB Output is correct
29 Correct 48 ms 12484 KB Output is correct
30 Correct 49 ms 12508 KB Output is correct
31 Correct 7 ms 6232 KB Output is correct
32 Correct 9 ms 6076 KB Output is correct
33 Correct 7 ms 6236 KB Output is correct
34 Correct 7 ms 6196 KB Output is correct
35 Correct 40 ms 8316 KB Output is correct
36 Correct 40 ms 8468 KB Output is correct
37 Correct 71 ms 9204 KB Output is correct
38 Correct 81 ms 9548 KB Output is correct
39 Correct 46 ms 10076 KB Output is correct
40 Correct 52 ms 9944 KB Output is correct
41 Correct 9 ms 5988 KB Output is correct
42 Correct 7 ms 5980 KB Output is correct
43 Correct 42 ms 8144 KB Output is correct
44 Correct 51 ms 8228 KB Output is correct
45 Correct 73 ms 9048 KB Output is correct
46 Correct 68 ms 9008 KB Output is correct
47 Correct 49 ms 9764 KB Output is correct
48 Correct 58 ms 9756 KB Output is correct
49 Correct 7 ms 5944 KB Output is correct
50 Correct 7 ms 5720 KB Output is correct
51 Correct 101 ms 19936 KB Output is correct
52 Correct 100 ms 20040 KB Output is correct
53 Correct 194 ms 23160 KB Output is correct
54 Correct 192 ms 23184 KB Output is correct
55 Correct 139 ms 23044 KB Output is correct
56 Correct 135 ms 23148 KB Output is correct
57 Correct 20 ms 8788 KB Output is correct
58 Correct 20 ms 8908 KB Output is correct
59 Correct 19 ms 8920 KB Output is correct
60 Correct 21 ms 8920 KB Output is correct
61 Correct 107 ms 13760 KB Output is correct
62 Correct 105 ms 14152 KB Output is correct
63 Correct 215 ms 16964 KB Output is correct
64 Correct 223 ms 17108 KB Output is correct
65 Correct 136 ms 17060 KB Output is correct
66 Correct 138 ms 16840 KB Output is correct
67 Correct 20 ms 7588 KB Output is correct
68 Correct 21 ms 7516 KB Output is correct
69 Correct 117 ms 13056 KB Output is correct
70 Correct 117 ms 13116 KB Output is correct
71 Correct 199 ms 16532 KB Output is correct
72 Correct 225 ms 16472 KB Output is correct
73 Correct 135 ms 16228 KB Output is correct
74 Correct 136 ms 16220 KB Output is correct
75 Correct 28 ms 7480 KB Output is correct
76 Correct 23 ms 7380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5212 KB Output is correct
2 Correct 4 ms 5212 KB Output is correct
3 Correct 4 ms 5212 KB Output is correct
4 Correct 4 ms 5212 KB Output is correct
5 Correct 4 ms 5212 KB Output is correct
6 Correct 4 ms 5212 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 5 ms 5208 KB Output is correct
10 Correct 4 ms 5212 KB Output is correct
11 Correct 4 ms 5224 KB Output is correct
12 Correct 4 ms 5208 KB Output is correct
13 Correct 3 ms 5212 KB Output is correct
14 Correct 3 ms 5188 KB Output is correct
15 Correct 3 ms 4952 KB Output is correct
16 Correct 3 ms 5164 KB Output is correct
17 Correct 4 ms 5184 KB Output is correct
18 Correct 5 ms 5208 KB Output is correct
19 Correct 5 ms 5212 KB Output is correct
20 Correct 4 ms 5212 KB Output is correct
21 Correct 4 ms 5268 KB Output is correct
22 Correct 4 ms 5216 KB Output is correct
23 Correct 4 ms 4960 KB Output is correct
24 Correct 3 ms 4956 KB Output is correct
25 Correct 4 ms 5464 KB Output is correct
26 Correct 4 ms 5184 KB Output is correct
27 Correct 4 ms 5212 KB Output is correct
28 Correct 4 ms 5212 KB Output is correct
29 Correct 4 ms 5212 KB Output is correct
30 Correct 5 ms 5212 KB Output is correct
31 Correct 4 ms 5212 KB Output is correct
32 Correct 4 ms 5176 KB Output is correct
33 Correct 4 ms 5344 KB Output is correct
34 Correct 4 ms 5212 KB Output is correct
35 Correct 4 ms 5164 KB Output is correct
36 Correct 4 ms 5212 KB Output is correct
37 Correct 4 ms 5212 KB Output is correct
38 Correct 4 ms 5208 KB Output is correct
39 Correct 4 ms 5212 KB Output is correct
40 Correct 4 ms 5288 KB Output is correct
41 Correct 3 ms 5212 KB Output is correct
42 Correct 4 ms 5212 KB Output is correct
43 Correct 4 ms 5212 KB Output is correct
44 Correct 4 ms 5212 KB Output is correct
45 Correct 4 ms 5212 KB Output is correct
46 Correct 4 ms 5212 KB Output is correct
47 Correct 4 ms 5212 KB Output is correct
48 Correct 4 ms 5212 KB Output is correct
49 Correct 4 ms 5068 KB Output is correct
50 Correct 4 ms 5180 KB Output is correct
51 Correct 43 ms 11040 KB Output is correct
52 Correct 47 ms 10808 KB Output is correct
53 Correct 74 ms 11720 KB Output is correct
54 Correct 71 ms 11852 KB Output is correct
55 Correct 48 ms 12484 KB Output is correct
56 Correct 49 ms 12508 KB Output is correct
57 Correct 7 ms 6232 KB Output is correct
58 Correct 9 ms 6076 KB Output is correct
59 Correct 7 ms 6236 KB Output is correct
60 Correct 7 ms 6196 KB Output is correct
61 Correct 40 ms 8316 KB Output is correct
62 Correct 40 ms 8468 KB Output is correct
63 Correct 71 ms 9204 KB Output is correct
64 Correct 81 ms 9548 KB Output is correct
65 Correct 46 ms 10076 KB Output is correct
66 Correct 52 ms 9944 KB Output is correct
67 Correct 9 ms 5988 KB Output is correct
68 Correct 7 ms 5980 KB Output is correct
69 Correct 42 ms 8144 KB Output is correct
70 Correct 51 ms 8228 KB Output is correct
71 Correct 73 ms 9048 KB Output is correct
72 Correct 68 ms 9008 KB Output is correct
73 Correct 49 ms 9764 KB Output is correct
74 Correct 58 ms 9756 KB Output is correct
75 Correct 7 ms 5944 KB Output is correct
76 Correct 7 ms 5720 KB Output is correct
77 Correct 101 ms 19936 KB Output is correct
78 Correct 100 ms 20040 KB Output is correct
79 Correct 194 ms 23160 KB Output is correct
80 Correct 192 ms 23184 KB Output is correct
81 Correct 139 ms 23044 KB Output is correct
82 Correct 135 ms 23148 KB Output is correct
83 Correct 20 ms 8788 KB Output is correct
84 Correct 20 ms 8908 KB Output is correct
85 Correct 19 ms 8920 KB Output is correct
86 Correct 21 ms 8920 KB Output is correct
87 Correct 107 ms 13760 KB Output is correct
88 Correct 105 ms 14152 KB Output is correct
89 Correct 215 ms 16964 KB Output is correct
90 Correct 223 ms 17108 KB Output is correct
91 Correct 136 ms 17060 KB Output is correct
92 Correct 138 ms 16840 KB Output is correct
93 Correct 20 ms 7588 KB Output is correct
94 Correct 21 ms 7516 KB Output is correct
95 Correct 117 ms 13056 KB Output is correct
96 Correct 117 ms 13116 KB Output is correct
97 Correct 199 ms 16532 KB Output is correct
98 Correct 225 ms 16472 KB Output is correct
99 Correct 135 ms 16228 KB Output is correct
100 Correct 136 ms 16220 KB Output is correct
101 Correct 28 ms 7480 KB Output is correct
102 Correct 23 ms 7380 KB Output is correct
103 Correct 113 ms 20680 KB Output is correct
104 Correct 99 ms 20668 KB Output is correct
105 Correct 259 ms 27300 KB Output is correct
106 Correct 212 ms 27320 KB Output is correct
107 Correct 167 ms 27052 KB Output is correct
108 Correct 131 ms 27092 KB Output is correct
109 Correct 21 ms 9736 KB Output is correct
110 Correct 21 ms 9764 KB Output is correct
111 Correct 21 ms 9688 KB Output is correct
112 Correct 28 ms 9724 KB Output is correct
113 Correct 111 ms 15036 KB Output is correct
114 Correct 102 ms 14688 KB Output is correct
115 Correct 259 ms 21324 KB Output is correct
116 Correct 252 ms 21768 KB Output is correct
117 Correct 158 ms 21060 KB Output is correct
118 Correct 151 ms 20724 KB Output is correct
119 Correct 23 ms 8540 KB Output is correct
120 Correct 21 ms 8540 KB Output is correct
121 Correct 112 ms 13768 KB Output is correct
122 Correct 123 ms 13756 KB Output is correct
123 Correct 217 ms 20672 KB Output is correct
124 Correct 222 ms 20708 KB Output is correct
125 Correct 141 ms 19876 KB Output is correct
126 Correct 161 ms 19876 KB Output is correct
127 Correct 25 ms 8400 KB Output is correct
128 Correct 24 ms 8496 KB Output is correct