Submission #962707

# Submission time Handle Problem Language Result Execution time Memory
962707 2024-04-14T07:19:49 Z Whisper Vinjete (COI22_vinjete) C++17
100 / 100
391 ms 206500 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = b; i >= a; i --)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPD(i, n) for (int i = n - 1; i >= 0; --i)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)

constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void setupIO(){
    #define name "Whisper"
    //Phu Trong from Nguyen Tat Thanh High School for gifted student
    srand(time(NULL));
    cin.tie(nullptr)->sync_with_stdio(false); cout.tie(nullptr);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);
    cout << fixed << setprecision(10);
}

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
int numNode, nLicense;
const int MAX = 1e5 + 5;
struct Edge{
    int u, v, l, r;
    Edge(){}
    Edge(int _u, int _v, int _l, int _r){
        u = _u;
        v = _v;
        l = _l;
        r = _r;
    }
    int other(int x){
        return (u ^ v ^ x);
    }
} edge[MAX];

vector<int> G[MAX];
int ans[MAX];
struct Node{
    int l, r, cnt, cover;
    Node(): l(-1), r(-1), cnt(0), cover(0){}
    Node(int _l, int _r, int _cnt, int _cover): l(_l), r(_r), cnt(_cnt), cover(_cover){}
};

struct SparseSegmentTree{
    vector<Node> st;
    int n;
    SparseSegmentTree(): st(MAX * 60), n(1){}

    void modify(int u, int v, int val, int id = 1, int l = 1, int r = 2e9){
        if (u > r || v < l) return;
        if (u <= l && v >= r) {
            st[id].cover += val;
            if (st[id].cover != 0) st[id].cnt = r - l + 1;
            else if(l != r) st[id].cnt = st[st[id].l].cnt + st[st[id].r].cnt;
            else st[id].cnt = 0;
            return;
        }
        if (st[id].l == -1) st[id].l = ++n;
        if (st[id].r == -1) st[id].r = ++n;
        int mid = (l + r) >> 1;
        modify(u, v, val, st[id].l, l, mid);
        modify(u, v, val, st[id].r, mid + 1, r);
        if (st[id].cover != 0) st[id].cnt = r - l + 1;
        else st[id].cnt = st[st[id].l].cnt + st[st[id].r].cnt;
    }

    int query(int u, int v, int id = 1, int l = 1, int r = 2e9){
        if (u > r || v < l) return 0;
        if (u <= l && v >= r) return st[id].cnt;
        int mid = (l + r) >> 1;
        if (st[id].l == -1) st[id].l = ++n;
        if (st[id].r == -1) st[id].r = ++n;

        int ql = query(u, v, st[id].l, l, mid);
        int qr = query(u, v, st[id].r, mid + 1, r);
        return (ql + qr);
    }
} st;
void dfs(int u, int p = -1){
    ans[u] = st.st[1].cnt;
    for (int&i : G[u]) {
        int v = edge[i].other(u);
        int l = edge[i].l, r = edge[i].r;
        if(v ^ p){
            st.modify(l, r, 1);
            dfs(v, u);
            st.modify(l, r, -1);
        }
    }
}
void Whisper(){
    cin >> numNode >> nLicense;
    for (int i = 1; i < numNode; ++i){
        cin >> edge[i].u >> edge[i].v >> edge[i].l >> edge[i].r;
        G[edge[i].u].emplace_back(i);
        G[edge[i].v].emplace_back(i);
    }
    dfs(1);
    for (int i = 2; i <= numNode; ++i) cout << ans[i] << '\n';
}


signed main(){
    setupIO();
    int Test = 1;
//    cin >> Test;
    for ( int i = 1 ; i <= Test ; i++ ){
        Whisper();
        if (i < Test) cout << '\n';
    }
}


# Verdict Execution time Memory Grader output
1 Correct 79 ms 192492 KB Output is correct
2 Correct 30 ms 192340 KB Output is correct
3 Correct 30 ms 192472 KB Output is correct
4 Correct 33 ms 192348 KB Output is correct
5 Correct 30 ms 192344 KB Output is correct
6 Correct 34 ms 192468 KB Output is correct
7 Correct 31 ms 192340 KB Output is correct
8 Correct 31 ms 192348 KB Output is correct
9 Correct 31 ms 192416 KB Output is correct
10 Correct 31 ms 192348 KB Output is correct
11 Correct 31 ms 192396 KB Output is correct
12 Correct 32 ms 192484 KB Output is correct
13 Correct 30 ms 192496 KB Output is correct
14 Correct 29 ms 192348 KB Output is correct
15 Correct 29 ms 192340 KB Output is correct
16 Correct 32 ms 192300 KB Output is correct
17 Correct 35 ms 192384 KB Output is correct
18 Correct 30 ms 192348 KB Output is correct
19 Correct 31 ms 192348 KB Output is correct
20 Correct 31 ms 192412 KB Output is correct
21 Correct 30 ms 192336 KB Output is correct
22 Correct 30 ms 192392 KB Output is correct
23 Correct 29 ms 192336 KB Output is correct
24 Correct 31 ms 192528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 192492 KB Output is correct
2 Correct 30 ms 192340 KB Output is correct
3 Correct 30 ms 192472 KB Output is correct
4 Correct 33 ms 192348 KB Output is correct
5 Correct 30 ms 192344 KB Output is correct
6 Correct 34 ms 192468 KB Output is correct
7 Correct 31 ms 192340 KB Output is correct
8 Correct 31 ms 192348 KB Output is correct
9 Correct 31 ms 192416 KB Output is correct
10 Correct 31 ms 192348 KB Output is correct
11 Correct 31 ms 192396 KB Output is correct
12 Correct 32 ms 192484 KB Output is correct
13 Correct 30 ms 192496 KB Output is correct
14 Correct 29 ms 192348 KB Output is correct
15 Correct 29 ms 192340 KB Output is correct
16 Correct 32 ms 192300 KB Output is correct
17 Correct 35 ms 192384 KB Output is correct
18 Correct 30 ms 192348 KB Output is correct
19 Correct 31 ms 192348 KB Output is correct
20 Correct 31 ms 192412 KB Output is correct
21 Correct 30 ms 192336 KB Output is correct
22 Correct 30 ms 192392 KB Output is correct
23 Correct 29 ms 192336 KB Output is correct
24 Correct 31 ms 192528 KB Output is correct
25 Correct 31 ms 192344 KB Output is correct
26 Correct 31 ms 192340 KB Output is correct
27 Correct 32 ms 192336 KB Output is correct
28 Correct 31 ms 192348 KB Output is correct
29 Correct 35 ms 192452 KB Output is correct
30 Correct 30 ms 192340 KB Output is correct
31 Correct 35 ms 192560 KB Output is correct
32 Correct 30 ms 192336 KB Output is correct
33 Correct 31 ms 192344 KB Output is correct
34 Correct 31 ms 192348 KB Output is correct
35 Correct 33 ms 192340 KB Output is correct
36 Correct 31 ms 192336 KB Output is correct
37 Correct 31 ms 192404 KB Output is correct
38 Correct 32 ms 192336 KB Output is correct
39 Correct 30 ms 192344 KB Output is correct
40 Correct 31 ms 192348 KB Output is correct
41 Correct 31 ms 192276 KB Output is correct
42 Correct 31 ms 192336 KB Output is correct
43 Correct 31 ms 192476 KB Output is correct
44 Correct 31 ms 192440 KB Output is correct
45 Correct 32 ms 192348 KB Output is correct
46 Correct 32 ms 192348 KB Output is correct
47 Correct 30 ms 192348 KB Output is correct
48 Correct 31 ms 192496 KB Output is correct
49 Correct 32 ms 192340 KB Output is correct
50 Correct 31 ms 192336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 192492 KB Output is correct
2 Correct 30 ms 192340 KB Output is correct
3 Correct 30 ms 192472 KB Output is correct
4 Correct 33 ms 192348 KB Output is correct
5 Correct 30 ms 192344 KB Output is correct
6 Correct 34 ms 192468 KB Output is correct
7 Correct 31 ms 192340 KB Output is correct
8 Correct 31 ms 192348 KB Output is correct
9 Correct 31 ms 192416 KB Output is correct
10 Correct 31 ms 192348 KB Output is correct
11 Correct 31 ms 192396 KB Output is correct
12 Correct 32 ms 192484 KB Output is correct
13 Correct 30 ms 192496 KB Output is correct
14 Correct 29 ms 192348 KB Output is correct
15 Correct 29 ms 192340 KB Output is correct
16 Correct 32 ms 192300 KB Output is correct
17 Correct 35 ms 192384 KB Output is correct
18 Correct 30 ms 192348 KB Output is correct
19 Correct 31 ms 192348 KB Output is correct
20 Correct 31 ms 192412 KB Output is correct
21 Correct 30 ms 192336 KB Output is correct
22 Correct 30 ms 192392 KB Output is correct
23 Correct 29 ms 192336 KB Output is correct
24 Correct 31 ms 192528 KB Output is correct
25 Correct 79 ms 197344 KB Output is correct
26 Correct 90 ms 197200 KB Output is correct
27 Correct 88 ms 197140 KB Output is correct
28 Correct 89 ms 197144 KB Output is correct
29 Correct 77 ms 197204 KB Output is correct
30 Correct 75 ms 197196 KB Output is correct
31 Correct 34 ms 192852 KB Output is correct
32 Correct 35 ms 192920 KB Output is correct
33 Correct 34 ms 192852 KB Output is correct
34 Correct 36 ms 192820 KB Output is correct
35 Correct 82 ms 194424 KB Output is correct
36 Correct 82 ms 194664 KB Output is correct
37 Correct 91 ms 194640 KB Output is correct
38 Correct 96 ms 194640 KB Output is correct
39 Correct 75 ms 194592 KB Output is correct
40 Correct 82 ms 194388 KB Output is correct
41 Correct 35 ms 192492 KB Output is correct
42 Correct 35 ms 192564 KB Output is correct
43 Correct 83 ms 194216 KB Output is correct
44 Correct 102 ms 194212 KB Output is correct
45 Correct 92 ms 194384 KB Output is correct
46 Correct 104 ms 194384 KB Output is correct
47 Correct 78 ms 194136 KB Output is correct
48 Correct 76 ms 194216 KB Output is correct
49 Correct 34 ms 192596 KB Output is correct
50 Correct 36 ms 192664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 192492 KB Output is correct
2 Correct 30 ms 192340 KB Output is correct
3 Correct 30 ms 192472 KB Output is correct
4 Correct 33 ms 192348 KB Output is correct
5 Correct 30 ms 192344 KB Output is correct
6 Correct 34 ms 192468 KB Output is correct
7 Correct 31 ms 192340 KB Output is correct
8 Correct 31 ms 192348 KB Output is correct
9 Correct 31 ms 192416 KB Output is correct
10 Correct 31 ms 192348 KB Output is correct
11 Correct 31 ms 192396 KB Output is correct
12 Correct 32 ms 192484 KB Output is correct
13 Correct 30 ms 192496 KB Output is correct
14 Correct 29 ms 192348 KB Output is correct
15 Correct 29 ms 192340 KB Output is correct
16 Correct 32 ms 192300 KB Output is correct
17 Correct 35 ms 192384 KB Output is correct
18 Correct 30 ms 192348 KB Output is correct
19 Correct 31 ms 192348 KB Output is correct
20 Correct 31 ms 192412 KB Output is correct
21 Correct 30 ms 192336 KB Output is correct
22 Correct 30 ms 192392 KB Output is correct
23 Correct 29 ms 192336 KB Output is correct
24 Correct 31 ms 192528 KB Output is correct
25 Correct 79 ms 197344 KB Output is correct
26 Correct 90 ms 197200 KB Output is correct
27 Correct 88 ms 197140 KB Output is correct
28 Correct 89 ms 197144 KB Output is correct
29 Correct 77 ms 197204 KB Output is correct
30 Correct 75 ms 197196 KB Output is correct
31 Correct 34 ms 192852 KB Output is correct
32 Correct 35 ms 192920 KB Output is correct
33 Correct 34 ms 192852 KB Output is correct
34 Correct 36 ms 192820 KB Output is correct
35 Correct 82 ms 194424 KB Output is correct
36 Correct 82 ms 194664 KB Output is correct
37 Correct 91 ms 194640 KB Output is correct
38 Correct 96 ms 194640 KB Output is correct
39 Correct 75 ms 194592 KB Output is correct
40 Correct 82 ms 194388 KB Output is correct
41 Correct 35 ms 192492 KB Output is correct
42 Correct 35 ms 192564 KB Output is correct
43 Correct 83 ms 194216 KB Output is correct
44 Correct 102 ms 194212 KB Output is correct
45 Correct 92 ms 194384 KB Output is correct
46 Correct 104 ms 194384 KB Output is correct
47 Correct 78 ms 194136 KB Output is correct
48 Correct 76 ms 194216 KB Output is correct
49 Correct 34 ms 192596 KB Output is correct
50 Correct 36 ms 192664 KB Output is correct
51 Correct 162 ms 206188 KB Output is correct
52 Correct 167 ms 206160 KB Output is correct
53 Correct 206 ms 206160 KB Output is correct
54 Correct 206 ms 206136 KB Output is correct
55 Correct 145 ms 206004 KB Output is correct
56 Correct 158 ms 205904 KB Output is correct
57 Correct 51 ms 194788 KB Output is correct
58 Correct 56 ms 194712 KB Output is correct
59 Correct 51 ms 194896 KB Output is correct
60 Correct 54 ms 194900 KB Output is correct
61 Correct 193 ms 199568 KB Output is correct
62 Correct 205 ms 199784 KB Output is correct
63 Correct 215 ms 199444 KB Output is correct
64 Correct 207 ms 199504 KB Output is correct
65 Correct 155 ms 199492 KB Output is correct
66 Correct 160 ms 199420 KB Output is correct
67 Correct 50 ms 193372 KB Output is correct
68 Correct 51 ms 193516 KB Output is correct
69 Correct 191 ms 198864 KB Output is correct
70 Correct 167 ms 198736 KB Output is correct
71 Correct 221 ms 198844 KB Output is correct
72 Correct 237 ms 198992 KB Output is correct
73 Correct 166 ms 198592 KB Output is correct
74 Correct 168 ms 198592 KB Output is correct
75 Correct 54 ms 193360 KB Output is correct
76 Correct 54 ms 193240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 192492 KB Output is correct
2 Correct 30 ms 192340 KB Output is correct
3 Correct 30 ms 192472 KB Output is correct
4 Correct 33 ms 192348 KB Output is correct
5 Correct 30 ms 192344 KB Output is correct
6 Correct 34 ms 192468 KB Output is correct
7 Correct 31 ms 192340 KB Output is correct
8 Correct 31 ms 192348 KB Output is correct
9 Correct 31 ms 192416 KB Output is correct
10 Correct 31 ms 192348 KB Output is correct
11 Correct 31 ms 192396 KB Output is correct
12 Correct 32 ms 192484 KB Output is correct
13 Correct 30 ms 192496 KB Output is correct
14 Correct 29 ms 192348 KB Output is correct
15 Correct 29 ms 192340 KB Output is correct
16 Correct 32 ms 192300 KB Output is correct
17 Correct 35 ms 192384 KB Output is correct
18 Correct 30 ms 192348 KB Output is correct
19 Correct 31 ms 192348 KB Output is correct
20 Correct 31 ms 192412 KB Output is correct
21 Correct 30 ms 192336 KB Output is correct
22 Correct 30 ms 192392 KB Output is correct
23 Correct 29 ms 192336 KB Output is correct
24 Correct 31 ms 192528 KB Output is correct
25 Correct 31 ms 192344 KB Output is correct
26 Correct 31 ms 192340 KB Output is correct
27 Correct 32 ms 192336 KB Output is correct
28 Correct 31 ms 192348 KB Output is correct
29 Correct 35 ms 192452 KB Output is correct
30 Correct 30 ms 192340 KB Output is correct
31 Correct 35 ms 192560 KB Output is correct
32 Correct 30 ms 192336 KB Output is correct
33 Correct 31 ms 192344 KB Output is correct
34 Correct 31 ms 192348 KB Output is correct
35 Correct 33 ms 192340 KB Output is correct
36 Correct 31 ms 192336 KB Output is correct
37 Correct 31 ms 192404 KB Output is correct
38 Correct 32 ms 192336 KB Output is correct
39 Correct 30 ms 192344 KB Output is correct
40 Correct 31 ms 192348 KB Output is correct
41 Correct 31 ms 192276 KB Output is correct
42 Correct 31 ms 192336 KB Output is correct
43 Correct 31 ms 192476 KB Output is correct
44 Correct 31 ms 192440 KB Output is correct
45 Correct 32 ms 192348 KB Output is correct
46 Correct 32 ms 192348 KB Output is correct
47 Correct 30 ms 192348 KB Output is correct
48 Correct 31 ms 192496 KB Output is correct
49 Correct 32 ms 192340 KB Output is correct
50 Correct 31 ms 192336 KB Output is correct
51 Correct 79 ms 197344 KB Output is correct
52 Correct 90 ms 197200 KB Output is correct
53 Correct 88 ms 197140 KB Output is correct
54 Correct 89 ms 197144 KB Output is correct
55 Correct 77 ms 197204 KB Output is correct
56 Correct 75 ms 197196 KB Output is correct
57 Correct 34 ms 192852 KB Output is correct
58 Correct 35 ms 192920 KB Output is correct
59 Correct 34 ms 192852 KB Output is correct
60 Correct 36 ms 192820 KB Output is correct
61 Correct 82 ms 194424 KB Output is correct
62 Correct 82 ms 194664 KB Output is correct
63 Correct 91 ms 194640 KB Output is correct
64 Correct 96 ms 194640 KB Output is correct
65 Correct 75 ms 194592 KB Output is correct
66 Correct 82 ms 194388 KB Output is correct
67 Correct 35 ms 192492 KB Output is correct
68 Correct 35 ms 192564 KB Output is correct
69 Correct 83 ms 194216 KB Output is correct
70 Correct 102 ms 194212 KB Output is correct
71 Correct 92 ms 194384 KB Output is correct
72 Correct 104 ms 194384 KB Output is correct
73 Correct 78 ms 194136 KB Output is correct
74 Correct 76 ms 194216 KB Output is correct
75 Correct 34 ms 192596 KB Output is correct
76 Correct 36 ms 192664 KB Output is correct
77 Correct 162 ms 206188 KB Output is correct
78 Correct 167 ms 206160 KB Output is correct
79 Correct 206 ms 206160 KB Output is correct
80 Correct 206 ms 206136 KB Output is correct
81 Correct 145 ms 206004 KB Output is correct
82 Correct 158 ms 205904 KB Output is correct
83 Correct 51 ms 194788 KB Output is correct
84 Correct 56 ms 194712 KB Output is correct
85 Correct 51 ms 194896 KB Output is correct
86 Correct 54 ms 194900 KB Output is correct
87 Correct 193 ms 199568 KB Output is correct
88 Correct 205 ms 199784 KB Output is correct
89 Correct 215 ms 199444 KB Output is correct
90 Correct 207 ms 199504 KB Output is correct
91 Correct 155 ms 199492 KB Output is correct
92 Correct 160 ms 199420 KB Output is correct
93 Correct 50 ms 193372 KB Output is correct
94 Correct 51 ms 193516 KB Output is correct
95 Correct 191 ms 198864 KB Output is correct
96 Correct 167 ms 198736 KB Output is correct
97 Correct 221 ms 198844 KB Output is correct
98 Correct 237 ms 198992 KB Output is correct
99 Correct 166 ms 198592 KB Output is correct
100 Correct 168 ms 198592 KB Output is correct
101 Correct 54 ms 193360 KB Output is correct
102 Correct 54 ms 193240 KB Output is correct
103 Correct 188 ms 206500 KB Output is correct
104 Correct 191 ms 206456 KB Output is correct
105 Correct 388 ms 206464 KB Output is correct
106 Correct 391 ms 206312 KB Output is correct
107 Correct 226 ms 206060 KB Output is correct
108 Correct 223 ms 206060 KB Output is correct
109 Correct 70 ms 194900 KB Output is correct
110 Correct 67 ms 194900 KB Output is correct
111 Correct 72 ms 194884 KB Output is correct
112 Correct 69 ms 194800 KB Output is correct
113 Correct 199 ms 200656 KB Output is correct
114 Correct 191 ms 200272 KB Output is correct
115 Correct 337 ms 200004 KB Output is correct
116 Correct 350 ms 200020 KB Output is correct
117 Correct 208 ms 199580 KB Output is correct
118 Correct 217 ms 199408 KB Output is correct
119 Correct 74 ms 193568 KB Output is correct
120 Correct 63 ms 193616 KB Output is correct
121 Correct 219 ms 199252 KB Output is correct
122 Correct 195 ms 199104 KB Output is correct
123 Correct 354 ms 199116 KB Output is correct
124 Correct 361 ms 199100 KB Output is correct
125 Correct 209 ms 198560 KB Output is correct
126 Correct 213 ms 198588 KB Output is correct
127 Correct 67 ms 193244 KB Output is correct
128 Correct 66 ms 193332 KB Output is correct