Submission #962705

# Submission time Handle Problem Language Result Execution time Memory
962705 2024-04-14T07:19:12 Z vjudge1 Vinjete (COI22_vinjete) C++17
100 / 100
441 ms 209636 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 31 ms 192340 KB Output is correct
2 Correct 30 ms 192340 KB Output is correct
3 Correct 34 ms 192344 KB Output is correct
4 Correct 31 ms 192344 KB Output is correct
5 Correct 34 ms 192344 KB Output is correct
6 Correct 35 ms 192336 KB Output is correct
7 Correct 29 ms 192244 KB Output is correct
8 Correct 29 ms 192204 KB Output is correct
9 Correct 30 ms 192340 KB Output is correct
10 Correct 32 ms 192348 KB Output is correct
11 Correct 32 ms 192376 KB Output is correct
12 Correct 30 ms 192344 KB Output is correct
13 Correct 36 ms 192336 KB Output is correct
14 Correct 33 ms 192540 KB Output is correct
15 Correct 29 ms 192204 KB Output is correct
16 Correct 32 ms 192424 KB Output is correct
17 Correct 31 ms 192296 KB Output is correct
18 Correct 31 ms 192400 KB Output is correct
19 Correct 30 ms 192348 KB Output is correct
20 Correct 30 ms 192340 KB Output is correct
21 Correct 30 ms 192340 KB Output is correct
22 Correct 31 ms 192448 KB Output is correct
23 Correct 29 ms 192272 KB Output is correct
24 Correct 29 ms 192428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 192340 KB Output is correct
2 Correct 30 ms 192340 KB Output is correct
3 Correct 34 ms 192344 KB Output is correct
4 Correct 31 ms 192344 KB Output is correct
5 Correct 34 ms 192344 KB Output is correct
6 Correct 35 ms 192336 KB Output is correct
7 Correct 29 ms 192244 KB Output is correct
8 Correct 29 ms 192204 KB Output is correct
9 Correct 30 ms 192340 KB Output is correct
10 Correct 32 ms 192348 KB Output is correct
11 Correct 32 ms 192376 KB Output is correct
12 Correct 30 ms 192344 KB Output is correct
13 Correct 36 ms 192336 KB Output is correct
14 Correct 33 ms 192540 KB Output is correct
15 Correct 29 ms 192204 KB Output is correct
16 Correct 32 ms 192424 KB Output is correct
17 Correct 31 ms 192296 KB Output is correct
18 Correct 31 ms 192400 KB Output is correct
19 Correct 30 ms 192348 KB Output is correct
20 Correct 30 ms 192340 KB Output is correct
21 Correct 30 ms 192340 KB Output is correct
22 Correct 31 ms 192448 KB Output is correct
23 Correct 29 ms 192272 KB Output is correct
24 Correct 29 ms 192428 KB Output is correct
25 Correct 30 ms 192340 KB Output is correct
26 Correct 31 ms 192596 KB Output is correct
27 Correct 32 ms 192604 KB Output is correct
28 Correct 32 ms 192552 KB Output is correct
29 Correct 31 ms 192340 KB Output is correct
30 Correct 32 ms 192340 KB Output is correct
31 Correct 36 ms 192596 KB Output is correct
32 Correct 36 ms 192592 KB Output is correct
33 Correct 35 ms 192468 KB Output is correct
34 Correct 33 ms 192592 KB Output is correct
35 Correct 31 ms 192568 KB Output is correct
36 Correct 32 ms 192452 KB Output is correct
37 Correct 31 ms 192680 KB Output is correct
38 Correct 33 ms 192488 KB Output is correct
39 Correct 31 ms 192312 KB Output is correct
40 Correct 32 ms 192436 KB Output is correct
41 Correct 32 ms 192408 KB Output is correct
42 Correct 33 ms 192596 KB Output is correct
43 Correct 32 ms 192340 KB Output is correct
44 Correct 31 ms 192336 KB Output is correct
45 Correct 35 ms 192324 KB Output is correct
46 Correct 37 ms 192512 KB Output is correct
47 Correct 32 ms 192340 KB Output is correct
48 Correct 31 ms 192460 KB Output is correct
49 Correct 32 ms 192360 KB Output is correct
50 Correct 32 ms 192356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 192340 KB Output is correct
2 Correct 30 ms 192340 KB Output is correct
3 Correct 34 ms 192344 KB Output is correct
4 Correct 31 ms 192344 KB Output is correct
5 Correct 34 ms 192344 KB Output is correct
6 Correct 35 ms 192336 KB Output is correct
7 Correct 29 ms 192244 KB Output is correct
8 Correct 29 ms 192204 KB Output is correct
9 Correct 30 ms 192340 KB Output is correct
10 Correct 32 ms 192348 KB Output is correct
11 Correct 32 ms 192376 KB Output is correct
12 Correct 30 ms 192344 KB Output is correct
13 Correct 36 ms 192336 KB Output is correct
14 Correct 33 ms 192540 KB Output is correct
15 Correct 29 ms 192204 KB Output is correct
16 Correct 32 ms 192424 KB Output is correct
17 Correct 31 ms 192296 KB Output is correct
18 Correct 31 ms 192400 KB Output is correct
19 Correct 30 ms 192348 KB Output is correct
20 Correct 30 ms 192340 KB Output is correct
21 Correct 30 ms 192340 KB Output is correct
22 Correct 31 ms 192448 KB Output is correct
23 Correct 29 ms 192272 KB Output is correct
24 Correct 29 ms 192428 KB Output is correct
25 Correct 81 ms 197204 KB Output is correct
26 Correct 81 ms 197200 KB Output is correct
27 Correct 91 ms 197100 KB Output is correct
28 Correct 91 ms 197340 KB Output is correct
29 Correct 82 ms 197168 KB Output is correct
30 Correct 75 ms 197200 KB Output is correct
31 Correct 34 ms 192964 KB Output is correct
32 Correct 34 ms 192848 KB Output is correct
33 Correct 34 ms 192848 KB Output is correct
34 Correct 34 ms 192808 KB Output is correct
35 Correct 81 ms 194648 KB Output is correct
36 Correct 81 ms 194748 KB Output is correct
37 Correct 98 ms 194440 KB Output is correct
38 Correct 97 ms 195028 KB Output is correct
39 Correct 73 ms 194640 KB Output is correct
40 Correct 75 ms 194388 KB Output is correct
41 Correct 36 ms 192592 KB Output is correct
42 Correct 34 ms 192560 KB Output is correct
43 Correct 92 ms 194384 KB Output is correct
44 Correct 83 ms 194212 KB Output is correct
45 Correct 114 ms 194228 KB Output is correct
46 Correct 94 ms 194220 KB Output is correct
47 Correct 90 ms 194216 KB Output is correct
48 Correct 81 ms 194132 KB Output is correct
49 Correct 36 ms 192600 KB Output is correct
50 Correct 39 ms 192600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 192340 KB Output is correct
2 Correct 30 ms 192340 KB Output is correct
3 Correct 34 ms 192344 KB Output is correct
4 Correct 31 ms 192344 KB Output is correct
5 Correct 34 ms 192344 KB Output is correct
6 Correct 35 ms 192336 KB Output is correct
7 Correct 29 ms 192244 KB Output is correct
8 Correct 29 ms 192204 KB Output is correct
9 Correct 30 ms 192340 KB Output is correct
10 Correct 32 ms 192348 KB Output is correct
11 Correct 32 ms 192376 KB Output is correct
12 Correct 30 ms 192344 KB Output is correct
13 Correct 36 ms 192336 KB Output is correct
14 Correct 33 ms 192540 KB Output is correct
15 Correct 29 ms 192204 KB Output is correct
16 Correct 32 ms 192424 KB Output is correct
17 Correct 31 ms 192296 KB Output is correct
18 Correct 31 ms 192400 KB Output is correct
19 Correct 30 ms 192348 KB Output is correct
20 Correct 30 ms 192340 KB Output is correct
21 Correct 30 ms 192340 KB Output is correct
22 Correct 31 ms 192448 KB Output is correct
23 Correct 29 ms 192272 KB Output is correct
24 Correct 29 ms 192428 KB Output is correct
25 Correct 81 ms 197204 KB Output is correct
26 Correct 81 ms 197200 KB Output is correct
27 Correct 91 ms 197100 KB Output is correct
28 Correct 91 ms 197340 KB Output is correct
29 Correct 82 ms 197168 KB Output is correct
30 Correct 75 ms 197200 KB Output is correct
31 Correct 34 ms 192964 KB Output is correct
32 Correct 34 ms 192848 KB Output is correct
33 Correct 34 ms 192848 KB Output is correct
34 Correct 34 ms 192808 KB Output is correct
35 Correct 81 ms 194648 KB Output is correct
36 Correct 81 ms 194748 KB Output is correct
37 Correct 98 ms 194440 KB Output is correct
38 Correct 97 ms 195028 KB Output is correct
39 Correct 73 ms 194640 KB Output is correct
40 Correct 75 ms 194388 KB Output is correct
41 Correct 36 ms 192592 KB Output is correct
42 Correct 34 ms 192560 KB Output is correct
43 Correct 92 ms 194384 KB Output is correct
44 Correct 83 ms 194212 KB Output is correct
45 Correct 114 ms 194228 KB Output is correct
46 Correct 94 ms 194220 KB Output is correct
47 Correct 90 ms 194216 KB Output is correct
48 Correct 81 ms 194132 KB Output is correct
49 Correct 36 ms 192600 KB Output is correct
50 Correct 39 ms 192600 KB Output is correct
51 Correct 168 ms 206192 KB Output is correct
52 Correct 170 ms 206188 KB Output is correct
53 Correct 199 ms 206236 KB Output is correct
54 Correct 196 ms 205956 KB Output is correct
55 Correct 156 ms 206116 KB Output is correct
56 Correct 148 ms 205904 KB Output is correct
57 Correct 51 ms 194676 KB Output is correct
58 Correct 62 ms 194900 KB Output is correct
59 Correct 56 ms 194784 KB Output is correct
60 Correct 59 ms 194664 KB Output is correct
61 Correct 178 ms 199632 KB Output is correct
62 Correct 185 ms 199808 KB Output is correct
63 Correct 211 ms 199508 KB Output is correct
64 Correct 205 ms 199588 KB Output is correct
65 Correct 158 ms 199508 KB Output is correct
66 Correct 176 ms 199280 KB Output is correct
67 Correct 65 ms 193400 KB Output is correct
68 Correct 50 ms 193456 KB Output is correct
69 Correct 187 ms 198844 KB Output is correct
70 Correct 202 ms 198836 KB Output is correct
71 Correct 218 ms 198736 KB Output is correct
72 Correct 250 ms 198848 KB Output is correct
73 Correct 190 ms 198592 KB Output is correct
74 Correct 192 ms 198584 KB Output is correct
75 Correct 59 ms 193364 KB Output is correct
76 Correct 67 ms 193208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 192340 KB Output is correct
2 Correct 30 ms 192340 KB Output is correct
3 Correct 34 ms 192344 KB Output is correct
4 Correct 31 ms 192344 KB Output is correct
5 Correct 34 ms 192344 KB Output is correct
6 Correct 35 ms 192336 KB Output is correct
7 Correct 29 ms 192244 KB Output is correct
8 Correct 29 ms 192204 KB Output is correct
9 Correct 30 ms 192340 KB Output is correct
10 Correct 32 ms 192348 KB Output is correct
11 Correct 32 ms 192376 KB Output is correct
12 Correct 30 ms 192344 KB Output is correct
13 Correct 36 ms 192336 KB Output is correct
14 Correct 33 ms 192540 KB Output is correct
15 Correct 29 ms 192204 KB Output is correct
16 Correct 32 ms 192424 KB Output is correct
17 Correct 31 ms 192296 KB Output is correct
18 Correct 31 ms 192400 KB Output is correct
19 Correct 30 ms 192348 KB Output is correct
20 Correct 30 ms 192340 KB Output is correct
21 Correct 30 ms 192340 KB Output is correct
22 Correct 31 ms 192448 KB Output is correct
23 Correct 29 ms 192272 KB Output is correct
24 Correct 29 ms 192428 KB Output is correct
25 Correct 30 ms 192340 KB Output is correct
26 Correct 31 ms 192596 KB Output is correct
27 Correct 32 ms 192604 KB Output is correct
28 Correct 32 ms 192552 KB Output is correct
29 Correct 31 ms 192340 KB Output is correct
30 Correct 32 ms 192340 KB Output is correct
31 Correct 36 ms 192596 KB Output is correct
32 Correct 36 ms 192592 KB Output is correct
33 Correct 35 ms 192468 KB Output is correct
34 Correct 33 ms 192592 KB Output is correct
35 Correct 31 ms 192568 KB Output is correct
36 Correct 32 ms 192452 KB Output is correct
37 Correct 31 ms 192680 KB Output is correct
38 Correct 33 ms 192488 KB Output is correct
39 Correct 31 ms 192312 KB Output is correct
40 Correct 32 ms 192436 KB Output is correct
41 Correct 32 ms 192408 KB Output is correct
42 Correct 33 ms 192596 KB Output is correct
43 Correct 32 ms 192340 KB Output is correct
44 Correct 31 ms 192336 KB Output is correct
45 Correct 35 ms 192324 KB Output is correct
46 Correct 37 ms 192512 KB Output is correct
47 Correct 32 ms 192340 KB Output is correct
48 Correct 31 ms 192460 KB Output is correct
49 Correct 32 ms 192360 KB Output is correct
50 Correct 32 ms 192356 KB Output is correct
51 Correct 81 ms 197204 KB Output is correct
52 Correct 81 ms 197200 KB Output is correct
53 Correct 91 ms 197100 KB Output is correct
54 Correct 91 ms 197340 KB Output is correct
55 Correct 82 ms 197168 KB Output is correct
56 Correct 75 ms 197200 KB Output is correct
57 Correct 34 ms 192964 KB Output is correct
58 Correct 34 ms 192848 KB Output is correct
59 Correct 34 ms 192848 KB Output is correct
60 Correct 34 ms 192808 KB Output is correct
61 Correct 81 ms 194648 KB Output is correct
62 Correct 81 ms 194748 KB Output is correct
63 Correct 98 ms 194440 KB Output is correct
64 Correct 97 ms 195028 KB Output is correct
65 Correct 73 ms 194640 KB Output is correct
66 Correct 75 ms 194388 KB Output is correct
67 Correct 36 ms 192592 KB Output is correct
68 Correct 34 ms 192560 KB Output is correct
69 Correct 92 ms 194384 KB Output is correct
70 Correct 83 ms 194212 KB Output is correct
71 Correct 114 ms 194228 KB Output is correct
72 Correct 94 ms 194220 KB Output is correct
73 Correct 90 ms 194216 KB Output is correct
74 Correct 81 ms 194132 KB Output is correct
75 Correct 36 ms 192600 KB Output is correct
76 Correct 39 ms 192600 KB Output is correct
77 Correct 168 ms 206192 KB Output is correct
78 Correct 170 ms 206188 KB Output is correct
79 Correct 199 ms 206236 KB Output is correct
80 Correct 196 ms 205956 KB Output is correct
81 Correct 156 ms 206116 KB Output is correct
82 Correct 148 ms 205904 KB Output is correct
83 Correct 51 ms 194676 KB Output is correct
84 Correct 62 ms 194900 KB Output is correct
85 Correct 56 ms 194784 KB Output is correct
86 Correct 59 ms 194664 KB Output is correct
87 Correct 178 ms 199632 KB Output is correct
88 Correct 185 ms 199808 KB Output is correct
89 Correct 211 ms 199508 KB Output is correct
90 Correct 205 ms 199588 KB Output is correct
91 Correct 158 ms 199508 KB Output is correct
92 Correct 176 ms 199280 KB Output is correct
93 Correct 65 ms 193400 KB Output is correct
94 Correct 50 ms 193456 KB Output is correct
95 Correct 187 ms 198844 KB Output is correct
96 Correct 202 ms 198836 KB Output is correct
97 Correct 218 ms 198736 KB Output is correct
98 Correct 250 ms 198848 KB Output is correct
99 Correct 190 ms 198592 KB Output is correct
100 Correct 192 ms 198584 KB Output is correct
101 Correct 59 ms 193364 KB Output is correct
102 Correct 67 ms 193208 KB Output is correct
103 Correct 197 ms 209028 KB Output is correct
104 Correct 219 ms 209036 KB Output is correct
105 Correct 441 ms 209636 KB Output is correct
106 Correct 403 ms 209604 KB Output is correct
107 Correct 242 ms 209160 KB Output is correct
108 Correct 244 ms 209100 KB Output is correct
109 Correct 74 ms 195524 KB Output is correct
110 Correct 74 ms 195400 KB Output is correct
111 Correct 78 ms 195408 KB Output is correct
112 Correct 74 ms 195548 KB Output is correct
113 Correct 214 ms 202888 KB Output is correct
114 Correct 200 ms 202624 KB Output is correct
115 Correct 350 ms 203004 KB Output is correct
116 Correct 356 ms 203272 KB Output is correct
117 Correct 238 ms 202552 KB Output is correct
118 Correct 226 ms 202312 KB Output is correct
119 Correct 80 ms 194176 KB Output is correct
120 Correct 65 ms 194124 KB Output is correct
121 Correct 227 ms 201784 KB Output is correct
122 Correct 215 ms 201608 KB Output is correct
123 Correct 364 ms 202412 KB Output is correct
124 Correct 417 ms 202408 KB Output is correct
125 Correct 216 ms 201684 KB Output is correct
126 Correct 219 ms 201692 KB Output is correct
127 Correct 70 ms 193996 KB Output is correct
128 Correct 68 ms 194048 KB Output is correct