Submission #962694

# Submission time Handle Problem Language Result Execution time Memory
962694 2024-04-14T07:10:46 Z vjudge1 Vinjete (COI22_vinjete) C++17
56 / 100
138 ms 33120 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 cnt, cover;
    Node(): cnt(0), cover(0){}
    Node(int _cnt, int _cover): cnt(_cnt), cover(_cover){}
};

struct SegmentTree{
    vector<Node> st;
    int n;
    SegmentTree(int _n = 0){
        this -> n = _n;
        st.resize((n << 2));
    }

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

    int query(int id, int l, int r, int u, int v){
        if (u > r || v < l) return 0;
        if (u <= l && v >= r) return st[id].cnt;
        int mid = (l + r) >> 1;
        int ql = query(id << 1, l, mid, u, v);
        int qr = query(id << 1 | 1, mid + 1, r, u, v);
        return (ql + qr);
    }
    void modify(int l, int r, int val){
        modify(1, 1, n, l, r, val);
    }
    int query(int l, int r){
        return query(1, 1, n, l, r);
    }
} 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);
    }
    st = SegmentTree(nLicense + 1);
    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 2 ms 4696 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 2 ms 4700 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4828 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 2 ms 4540 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 2 ms 4700 KB Output is correct
13 Correct 2 ms 4700 KB Output is correct
14 Correct 2 ms 4700 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4696 KB Output is correct
18 Correct 2 ms 4700 KB Output is correct
19 Correct 2 ms 4700 KB Output is correct
20 Correct 3 ms 4700 KB Output is correct
21 Correct 2 ms 4700 KB Output is correct
22 Correct 2 ms 4696 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4696 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 2 ms 4700 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4828 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 2 ms 4540 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 2 ms 4700 KB Output is correct
13 Correct 2 ms 4700 KB Output is correct
14 Correct 2 ms 4700 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4696 KB Output is correct
18 Correct 2 ms 4700 KB Output is correct
19 Correct 2 ms 4700 KB Output is correct
20 Correct 3 ms 4700 KB Output is correct
21 Correct 2 ms 4700 KB Output is correct
22 Correct 2 ms 4696 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Runtime error 6 ms 9052 KB Execution killed with signal 6
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4696 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 2 ms 4700 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4828 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 2 ms 4540 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 2 ms 4700 KB Output is correct
13 Correct 2 ms 4700 KB Output is correct
14 Correct 2 ms 4700 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4696 KB Output is correct
18 Correct 2 ms 4700 KB Output is correct
19 Correct 2 ms 4700 KB Output is correct
20 Correct 3 ms 4700 KB Output is correct
21 Correct 2 ms 4700 KB Output is correct
22 Correct 2 ms 4696 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 34 ms 15188 KB Output is correct
26 Correct 41 ms 15136 KB Output is correct
27 Correct 42 ms 15264 KB Output is correct
28 Correct 41 ms 15188 KB Output is correct
29 Correct 35 ms 15184 KB Output is correct
30 Correct 36 ms 15184 KB Output is correct
31 Correct 5 ms 8228 KB Output is correct
32 Correct 5 ms 8028 KB Output is correct
33 Correct 7 ms 8116 KB Output is correct
34 Correct 6 ms 8028 KB Output is correct
35 Correct 32 ms 10328 KB Output is correct
36 Correct 33 ms 10580 KB Output is correct
37 Correct 50 ms 10440 KB Output is correct
38 Correct 43 ms 10588 KB Output is correct
39 Correct 29 ms 10468 KB Output is correct
40 Correct 29 ms 10320 KB Output is correct
41 Correct 5 ms 7512 KB Output is correct
42 Correct 5 ms 7516 KB Output is correct
43 Correct 34 ms 9820 KB Output is correct
44 Correct 45 ms 9660 KB Output is correct
45 Correct 47 ms 9812 KB Output is correct
46 Correct 43 ms 9772 KB Output is correct
47 Correct 29 ms 9816 KB Output is correct
48 Correct 29 ms 9808 KB Output is correct
49 Correct 5 ms 7256 KB Output is correct
50 Correct 8 ms 7404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4696 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 2 ms 4700 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4828 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 2 ms 4540 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 2 ms 4700 KB Output is correct
13 Correct 2 ms 4700 KB Output is correct
14 Correct 2 ms 4700 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4696 KB Output is correct
18 Correct 2 ms 4700 KB Output is correct
19 Correct 2 ms 4700 KB Output is correct
20 Correct 3 ms 4700 KB Output is correct
21 Correct 2 ms 4700 KB Output is correct
22 Correct 2 ms 4696 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 34 ms 15188 KB Output is correct
26 Correct 41 ms 15136 KB Output is correct
27 Correct 42 ms 15264 KB Output is correct
28 Correct 41 ms 15188 KB Output is correct
29 Correct 35 ms 15184 KB Output is correct
30 Correct 36 ms 15184 KB Output is correct
31 Correct 5 ms 8228 KB Output is correct
32 Correct 5 ms 8028 KB Output is correct
33 Correct 7 ms 8116 KB Output is correct
34 Correct 6 ms 8028 KB Output is correct
35 Correct 32 ms 10328 KB Output is correct
36 Correct 33 ms 10580 KB Output is correct
37 Correct 50 ms 10440 KB Output is correct
38 Correct 43 ms 10588 KB Output is correct
39 Correct 29 ms 10468 KB Output is correct
40 Correct 29 ms 10320 KB Output is correct
41 Correct 5 ms 7512 KB Output is correct
42 Correct 5 ms 7516 KB Output is correct
43 Correct 34 ms 9820 KB Output is correct
44 Correct 45 ms 9660 KB Output is correct
45 Correct 47 ms 9812 KB Output is correct
46 Correct 43 ms 9772 KB Output is correct
47 Correct 29 ms 9816 KB Output is correct
48 Correct 29 ms 9808 KB Output is correct
49 Correct 5 ms 7256 KB Output is correct
50 Correct 8 ms 7404 KB Output is correct
51 Correct 87 ms 32924 KB Output is correct
52 Correct 87 ms 32732 KB Output is correct
53 Correct 128 ms 33108 KB Output is correct
54 Correct 110 ms 33120 KB Output is correct
55 Correct 87 ms 32984 KB Output is correct
56 Correct 82 ms 32852 KB Output is correct
57 Correct 16 ms 14940 KB Output is correct
58 Correct 16 ms 14940 KB Output is correct
59 Correct 16 ms 14940 KB Output is correct
60 Correct 16 ms 14936 KB Output is correct
61 Correct 87 ms 20816 KB Output is correct
62 Correct 88 ms 21280 KB Output is correct
63 Correct 138 ms 20728 KB Output is correct
64 Correct 117 ms 21008 KB Output is correct
65 Correct 83 ms 21048 KB Output is correct
66 Correct 88 ms 20648 KB Output is correct
67 Correct 16 ms 12380 KB Output is correct
68 Correct 16 ms 12380 KB Output is correct
69 Correct 96 ms 19252 KB Output is correct
70 Correct 102 ms 19260 KB Output is correct
71 Correct 134 ms 19536 KB Output is correct
72 Correct 123 ms 19556 KB Output is correct
73 Correct 88 ms 19284 KB Output is correct
74 Correct 104 ms 19288 KB Output is correct
75 Correct 17 ms 12120 KB Output is correct
76 Correct 18 ms 12124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4696 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 2 ms 4700 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4828 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 2 ms 4540 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 2 ms 4700 KB Output is correct
13 Correct 2 ms 4700 KB Output is correct
14 Correct 2 ms 4700 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4696 KB Output is correct
18 Correct 2 ms 4700 KB Output is correct
19 Correct 2 ms 4700 KB Output is correct
20 Correct 3 ms 4700 KB Output is correct
21 Correct 2 ms 4700 KB Output is correct
22 Correct 2 ms 4696 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Runtime error 6 ms 9052 KB Execution killed with signal 6
26 Halted 0 ms 0 KB -