Submission #953469

# Submission time Handle Problem Language Result Execution time Memory
953469 2024-03-26T02:57:34 Z dwuy Vinjete (COI22_vinjete) C++14
100 / 100
531 ms 193920 KB
/**   - dwuy -

      />    フ
      |  _  _|
      /`ミ _x ノ
     /      |
    /   ヽ   ?
 / ̄|   | | |
 | ( ̄ヽ__ヽ_)_)
 \二つ

**/
#include <bits/stdc++.h>

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout)
#define fi first
#define se second
#define endl "\n"
#define len(s) int32_t(s.length())
#define MASK(k)(1LL<<(k))
#define TASK "test"
#define int long long

using namespace std;

typedef tuple<int, int, int> tpiii;
typedef pair<double, double> pdd;
typedef pair<int, int> pii;
typedef long long ll;

const long long OO = 1e18;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MX = 100005;  

struct Node{
    int cnt;
    int sum;
    Node *l, *r;

    Node(){
        this->cnt = 0;
        this->sum = 0;
        this->l = this->r = NULL;
    }
};

struct SMT{
    Node *root;
    int n;

    SMT(int n = 0){
        this->n = n;
        this->root = new Node();
    }
    
    Node *update(int l, int r, Node *cur, const int &u, const int &v, const int &val){
        if(l>v || r<u) return cur;
        if(cur == NULL) cur = new Node();
        if(l>=u && r<=v){
            cur->cnt += val;
            cur->sum = cur->cnt? r - l + 1 : (cur->l? cur->l->sum : 0) + (cur->r? cur->r->sum : 0);
            return cur;
        }
        int mid = (l+r)>>1;
        cur->l = update(l, mid, cur->l, u, v, val);
        cur->r = update(mid+1, r, cur->r, u, v, val);
        cur->sum = cur->cnt? r - l + 1 : (cur->l? cur->l->sum : 0) + (cur->r? cur->r->sum : 0);
        return cur;
    }

    void update(int l, int r, int val){
        root = update(1, n, root, l, r, val);
    }

    int get(int l, int r, Node *cur, const int &u, const int &v){
        if(l>v || r<u || cur == NULL) return 0;
        if(l>=u && r<=v) return cur->sum;
        int mid = (l+r)>>1;
        if(cur->cnt) return min(r, v) - max(l, u) + 1;
        return get(l, mid, cur->l, u, v) + get(mid+1, r, cur->r, u, v);
    }

    int get(int l, int r){
        return get(1, n, root, l, r);
    }
};

int n, m;
int ans[MX];
pii val[MX];
pii edges[MX];
vector<int> G[MX];

void nhap(){
    cin >> n >> m;
    for(int i=1; i<n; i++){
        int u, v, l, r;
        cin >> u >> v >> l >> r;
        G[u].push_back(i);
        G[v].push_back(i);
        edges[i] = {u, v};
        val[i] = {l, r};
    }
}

SMT smt(1000000000);

void dfs(int u, int p){
    ans[u] = smt.root->sum;
    for(int i: G[u]){
        int v = edges[i].fi ^ edges[i].se ^ u;
        if(v == p) continue;
        int l, r; tie(l, r) = val[i];
        smt.update(l, r, 1);        
        dfs(v, u);
        smt.update(l, r, -1);
    }
}

void solve(){
    dfs(1, 0);
    for(int i=2; i<=n; i++) cout << ans[i] << endl;
}

int32_t main(){
    fastIO;
    //file(TASK);
    
    nhap();
    solve();

    return 0;
}




# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 3 ms 5004 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 2 ms 4700 KB Output is correct
9 Correct 3 ms 4700 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 2 ms 4696 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 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
18 Correct 2 ms 4700 KB Output is correct
19 Correct 2 ms 4696 KB Output is correct
20 Correct 2 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 4700 KB Output is correct
24 Correct 2 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 3 ms 5004 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 2 ms 4700 KB Output is correct
9 Correct 3 ms 4700 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 2 ms 4696 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 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
18 Correct 2 ms 4700 KB Output is correct
19 Correct 2 ms 4696 KB Output is correct
20 Correct 2 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 4700 KB Output is correct
24 Correct 2 ms 4700 KB Output is correct
25 Correct 3 ms 5212 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 5 ms 7524 KB Output is correct
28 Correct 5 ms 7516 KB Output is correct
29 Correct 3 ms 5980 KB Output is correct
30 Correct 3 ms 5980 KB Output is correct
31 Correct 6 ms 7516 KB Output is correct
32 Correct 4 ms 7516 KB Output is correct
33 Correct 4 ms 7516 KB Output is correct
34 Correct 4 ms 7512 KB Output is correct
35 Correct 2 ms 4700 KB Output is correct
36 Correct 2 ms 4700 KB Output is correct
37 Correct 5 ms 7312 KB Output is correct
38 Correct 5 ms 7260 KB Output is correct
39 Correct 3 ms 5724 KB Output is correct
40 Correct 3 ms 5812 KB Output is correct
41 Correct 5 ms 7260 KB Output is correct
42 Correct 5 ms 7260 KB Output is correct
43 Correct 2 ms 4696 KB Output is correct
44 Correct 2 ms 4700 KB Output is correct
45 Correct 5 ms 7260 KB Output is correct
46 Correct 5 ms 7256 KB Output is correct
47 Correct 4 ms 5720 KB Output is correct
48 Correct 3 ms 5756 KB Output is correct
49 Correct 4 ms 7256 KB Output is correct
50 Correct 5 ms 7260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 3 ms 5004 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 2 ms 4700 KB Output is correct
9 Correct 3 ms 4700 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 2 ms 4696 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 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
18 Correct 2 ms 4700 KB Output is correct
19 Correct 2 ms 4696 KB Output is correct
20 Correct 2 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 4700 KB Output is correct
24 Correct 2 ms 4700 KB Output is correct
25 Correct 41 ms 15696 KB Output is correct
26 Correct 43 ms 15512 KB Output is correct
27 Correct 54 ms 18552 KB Output is correct
28 Correct 60 ms 18524 KB Output is correct
29 Correct 41 ms 18696 KB Output is correct
30 Correct 40 ms 18512 KB Output is correct
31 Correct 6 ms 7516 KB Output is correct
32 Correct 7 ms 7516 KB Output is correct
33 Correct 6 ms 7512 KB Output is correct
34 Correct 7 ms 7516 KB Output is correct
35 Correct 38 ms 8416 KB Output is correct
36 Correct 38 ms 8856 KB Output is correct
37 Correct 60 ms 11344 KB Output is correct
38 Correct 54 ms 11860 KB Output is correct
39 Correct 38 ms 11600 KB Output is correct
40 Correct 38 ms 11348 KB Output is correct
41 Correct 6 ms 6492 KB Output is correct
42 Correct 6 ms 6492 KB Output is correct
43 Correct 40 ms 7772 KB Output is correct
44 Correct 40 ms 7764 KB Output is correct
45 Correct 60 ms 10836 KB Output is correct
46 Correct 54 ms 10836 KB Output is correct
47 Correct 38 ms 10576 KB Output is correct
48 Correct 38 ms 10628 KB Output is correct
49 Correct 6 ms 6488 KB Output is correct
50 Correct 7 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 3 ms 5004 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 2 ms 4700 KB Output is correct
9 Correct 3 ms 4700 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 2 ms 4696 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 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
18 Correct 2 ms 4700 KB Output is correct
19 Correct 2 ms 4696 KB Output is correct
20 Correct 2 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 4700 KB Output is correct
24 Correct 2 ms 4700 KB Output is correct
25 Correct 41 ms 15696 KB Output is correct
26 Correct 43 ms 15512 KB Output is correct
27 Correct 54 ms 18552 KB Output is correct
28 Correct 60 ms 18524 KB Output is correct
29 Correct 41 ms 18696 KB Output is correct
30 Correct 40 ms 18512 KB Output is correct
31 Correct 6 ms 7516 KB Output is correct
32 Correct 7 ms 7516 KB Output is correct
33 Correct 6 ms 7512 KB Output is correct
34 Correct 7 ms 7516 KB Output is correct
35 Correct 38 ms 8416 KB Output is correct
36 Correct 38 ms 8856 KB Output is correct
37 Correct 60 ms 11344 KB Output is correct
38 Correct 54 ms 11860 KB Output is correct
39 Correct 38 ms 11600 KB Output is correct
40 Correct 38 ms 11348 KB Output is correct
41 Correct 6 ms 6492 KB Output is correct
42 Correct 6 ms 6492 KB Output is correct
43 Correct 40 ms 7772 KB Output is correct
44 Correct 40 ms 7764 KB Output is correct
45 Correct 60 ms 10836 KB Output is correct
46 Correct 54 ms 10836 KB Output is correct
47 Correct 38 ms 10576 KB Output is correct
48 Correct 38 ms 10628 KB Output is correct
49 Correct 6 ms 6488 KB Output is correct
50 Correct 7 ms 6492 KB Output is correct
51 Correct 107 ms 32824 KB Output is correct
52 Correct 103 ms 32852 KB Output is correct
53 Correct 149 ms 40292 KB Output is correct
54 Correct 151 ms 40276 KB Output is correct
55 Correct 110 ms 40236 KB Output is correct
56 Correct 107 ms 40364 KB Output is correct
57 Correct 21 ms 14684 KB Output is correct
58 Correct 21 ms 14736 KB Output is correct
59 Correct 21 ms 14684 KB Output is correct
60 Correct 22 ms 14680 KB Output is correct
61 Correct 96 ms 15444 KB Output is correct
62 Correct 100 ms 15896 KB Output is correct
63 Correct 158 ms 22352 KB Output is correct
64 Correct 165 ms 22708 KB Output is correct
65 Correct 108 ms 22964 KB Output is correct
66 Correct 117 ms 22424 KB Output is correct
67 Correct 31 ms 11092 KB Output is correct
68 Correct 24 ms 11088 KB Output is correct
69 Correct 109 ms 13000 KB Output is correct
70 Correct 107 ms 13020 KB Output is correct
71 Correct 161 ms 20676 KB Output is correct
72 Correct 170 ms 20672 KB Output is correct
73 Correct 120 ms 20304 KB Output is correct
74 Correct 130 ms 20308 KB Output is correct
75 Correct 25 ms 10760 KB Output is correct
76 Correct 24 ms 10844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 3 ms 5004 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 2 ms 4700 KB Output is correct
9 Correct 3 ms 4700 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 2 ms 4696 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 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
18 Correct 2 ms 4700 KB Output is correct
19 Correct 2 ms 4696 KB Output is correct
20 Correct 2 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 4700 KB Output is correct
24 Correct 2 ms 4700 KB Output is correct
25 Correct 3 ms 5212 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 5 ms 7524 KB Output is correct
28 Correct 5 ms 7516 KB Output is correct
29 Correct 3 ms 5980 KB Output is correct
30 Correct 3 ms 5980 KB Output is correct
31 Correct 6 ms 7516 KB Output is correct
32 Correct 4 ms 7516 KB Output is correct
33 Correct 4 ms 7516 KB Output is correct
34 Correct 4 ms 7512 KB Output is correct
35 Correct 2 ms 4700 KB Output is correct
36 Correct 2 ms 4700 KB Output is correct
37 Correct 5 ms 7312 KB Output is correct
38 Correct 5 ms 7260 KB Output is correct
39 Correct 3 ms 5724 KB Output is correct
40 Correct 3 ms 5812 KB Output is correct
41 Correct 5 ms 7260 KB Output is correct
42 Correct 5 ms 7260 KB Output is correct
43 Correct 2 ms 4696 KB Output is correct
44 Correct 2 ms 4700 KB Output is correct
45 Correct 5 ms 7260 KB Output is correct
46 Correct 5 ms 7256 KB Output is correct
47 Correct 4 ms 5720 KB Output is correct
48 Correct 3 ms 5756 KB Output is correct
49 Correct 4 ms 7256 KB Output is correct
50 Correct 5 ms 7260 KB Output is correct
51 Correct 41 ms 15696 KB Output is correct
52 Correct 43 ms 15512 KB Output is correct
53 Correct 54 ms 18552 KB Output is correct
54 Correct 60 ms 18524 KB Output is correct
55 Correct 41 ms 18696 KB Output is correct
56 Correct 40 ms 18512 KB Output is correct
57 Correct 6 ms 7516 KB Output is correct
58 Correct 7 ms 7516 KB Output is correct
59 Correct 6 ms 7512 KB Output is correct
60 Correct 7 ms 7516 KB Output is correct
61 Correct 38 ms 8416 KB Output is correct
62 Correct 38 ms 8856 KB Output is correct
63 Correct 60 ms 11344 KB Output is correct
64 Correct 54 ms 11860 KB Output is correct
65 Correct 38 ms 11600 KB Output is correct
66 Correct 38 ms 11348 KB Output is correct
67 Correct 6 ms 6492 KB Output is correct
68 Correct 6 ms 6492 KB Output is correct
69 Correct 40 ms 7772 KB Output is correct
70 Correct 40 ms 7764 KB Output is correct
71 Correct 60 ms 10836 KB Output is correct
72 Correct 54 ms 10836 KB Output is correct
73 Correct 38 ms 10576 KB Output is correct
74 Correct 38 ms 10628 KB Output is correct
75 Correct 6 ms 6488 KB Output is correct
76 Correct 7 ms 6492 KB Output is correct
77 Correct 107 ms 32824 KB Output is correct
78 Correct 103 ms 32852 KB Output is correct
79 Correct 149 ms 40292 KB Output is correct
80 Correct 151 ms 40276 KB Output is correct
81 Correct 110 ms 40236 KB Output is correct
82 Correct 107 ms 40364 KB Output is correct
83 Correct 21 ms 14684 KB Output is correct
84 Correct 21 ms 14736 KB Output is correct
85 Correct 21 ms 14684 KB Output is correct
86 Correct 22 ms 14680 KB Output is correct
87 Correct 96 ms 15444 KB Output is correct
88 Correct 100 ms 15896 KB Output is correct
89 Correct 158 ms 22352 KB Output is correct
90 Correct 165 ms 22708 KB Output is correct
91 Correct 108 ms 22964 KB Output is correct
92 Correct 117 ms 22424 KB Output is correct
93 Correct 31 ms 11092 KB Output is correct
94 Correct 24 ms 11088 KB Output is correct
95 Correct 109 ms 13000 KB Output is correct
96 Correct 107 ms 13020 KB Output is correct
97 Correct 161 ms 20676 KB Output is correct
98 Correct 170 ms 20672 KB Output is correct
99 Correct 120 ms 20304 KB Output is correct
100 Correct 130 ms 20308 KB Output is correct
101 Correct 25 ms 10760 KB Output is correct
102 Correct 24 ms 10844 KB Output is correct
103 Correct 123 ms 33636 KB Output is correct
104 Correct 125 ms 33616 KB Output is correct
105 Correct 515 ms 193920 KB Output is correct
106 Correct 531 ms 193920 KB Output is correct
107 Correct 254 ms 101460 KB Output is correct
108 Correct 247 ms 101460 KB Output is correct
109 Correct 71 ms 48960 KB Output is correct
110 Correct 72 ms 49040 KB Output is correct
111 Correct 63 ms 48948 KB Output is correct
112 Correct 71 ms 48976 KB Output is correct
113 Correct 123 ms 16976 KB Output is correct
114 Correct 124 ms 16180 KB Output is correct
115 Correct 419 ms 176720 KB Output is correct
116 Correct 426 ms 176976 KB Output is correct
117 Correct 202 ms 84044 KB Output is correct
118 Correct 199 ms 83540 KB Output is correct
119 Correct 57 ms 45800 KB Output is correct
120 Correct 58 ms 45472 KB Output is correct
121 Correct 123 ms 13652 KB Output is correct
122 Correct 123 ms 13648 KB Output is correct
123 Correct 421 ms 174324 KB Output is correct
124 Correct 420 ms 174676 KB Output is correct
125 Correct 207 ms 81568 KB Output is correct
126 Correct 217 ms 81520 KB Output is correct
127 Correct 61 ms 44884 KB Output is correct
128 Correct 62 ms 45000 KB Output is correct