Submission #813096

# Submission time Handle Problem Language Result Execution time Memory
813096 2023-08-07T13:29:25 Z stefanopulos Vinjete (COI22_vinjete) C++17
69 / 100
253 ms 185020 KB
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ldb;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ldb,ldb> pdd;

#define ff(i,a,b) for(int i = a; i <= b; i++)
#define fb(i,b,a) for(int i = b; i >= a; i--)
#define trav(a,x) for(auto& a : x)
 
#define sz(a) (int)(a).size()
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k)  print the k-th smallest number in os(0-based)

const int mod = 1000000007;
const int inf = 1e9 + 5;
const int mxN = 200005; 

int n, m;

vector<array<int,3>> g[mxN];

int idx = 0;
int root;
int ls[20 * mxN];
int rs[20 * mxN];
int mn[20 * mxN];
int cnt[20 * mxN];
int lenj[20 * mxN];

void propagate(int v, int tl, int tr){
    if(lenj[v] != 0){
        mn[v] += lenj[v];

        if(tl != tr){
            int mid = (tl + tr) / 2;

            if(!ls[v]){
                ls[v] = ++idx;
                mn[ls[v]] = 0;
                cnt[ls[v]] = mid - tl + 1;
            }
            lenj[ls[v]] += lenj[v];

            if(!rs[v]){
                rs[v] = ++idx;
                mn[rs[v]] = 0;
                cnt[rs[v]] = tr - mid;
            }
            lenj[rs[v]] += lenj[v];

        }

        lenj[v] = 0;
    }
}

void lazyupd(int& v, int tl, int tr, int l, int r, int val){
    if(!v){
        v = ++idx;
        mn[v] = 0;
        cnt[v] = tr - tl + 1;
    }

    propagate(v, tl, tr);
    if(tl > tr || l > tr || tl > r)return;
    if(tl >= l && tr <= r){
        lenj[v] += val;
        propagate(v, tl, tr);
        return;
    }
    int mid = (tl + tr) / 2;
    lazyupd(ls[v], tl, mid, l, r, val); lazyupd(rs[v], mid + 1, tr, l, r, val);
    
    mn[v] = min(mn[ls[v]], mn[rs[v]]);
    cnt[v] = (mn[v] == mn[ls[v]] ? cnt[ls[v]] : 0) 
    + (mn[v] == mn[rs[v]] ? cnt[rs[v]] : 0);
}

int res[mxN];
void dfs(int v, int p){

    res[v] = m - (mn[root] == 0 ? cnt[root] : 0);
    for(auto c : g[v]){
        int u = c[0];
        int l = c[1];
        int r = c[2];
        if(u != p){
            lazyupd(root,1,m,l,r,1);
            dfs(u, v);
            lazyupd(root,1,m,l,r,-1);
        }
    }

}

int main(){
    cin.tie(0)->sync_with_stdio(0);

    cin >> n >> m;
    ff(i,1,n - 1){
        int u, v, l, r;
        cin >> u >> v >> l >> r;
        g[u].pb({v, l, r});
        g[v].pb({u, l, r});
    }

    dfs(1, -1);

    ff(i,2,n)cout << res[i] << '\n';

    return 0;
}
/*

3 8
2 1 1 7
3 2 3 8

// probati bojenje sahovski
*/
 
 
 
 
 
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5204 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 3 ms 5204 KB Output is correct
6 Correct 3 ms 5204 KB Output is correct
7 Correct 2 ms 5076 KB Output is correct
8 Correct 2 ms 5076 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 4 ms 5128 KB Output is correct
11 Correct 4 ms 5084 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 2 ms 5076 KB Output is correct
16 Correct 2 ms 5016 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 3 ms 5044 KB Output is correct
19 Correct 4 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5076 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 2 ms 5076 KB Output is correct
24 Correct 2 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5204 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 3 ms 5204 KB Output is correct
6 Correct 3 ms 5204 KB Output is correct
7 Correct 2 ms 5076 KB Output is correct
8 Correct 2 ms 5076 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 4 ms 5128 KB Output is correct
11 Correct 4 ms 5084 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 2 ms 5076 KB Output is correct
16 Correct 2 ms 5016 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 3 ms 5044 KB Output is correct
19 Correct 4 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5076 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 2 ms 5076 KB Output is correct
24 Correct 2 ms 5076 KB Output is correct
25 Correct 4 ms 5076 KB Output is correct
26 Correct 4 ms 5204 KB Output is correct
27 Correct 7 ms 7892 KB Output is correct
28 Correct 8 ms 7892 KB Output is correct
29 Correct 5 ms 5972 KB Output is correct
30 Correct 4 ms 5972 KB Output is correct
31 Correct 6 ms 7224 KB Output is correct
32 Correct 6 ms 7252 KB Output is correct
33 Correct 8 ms 7252 KB Output is correct
34 Correct 5 ms 7252 KB Output is correct
35 Correct 7 ms 5168 KB Output is correct
36 Correct 5 ms 5076 KB Output is correct
37 Correct 10 ms 7732 KB Output is correct
38 Correct 7 ms 7764 KB Output is correct
39 Correct 4 ms 5936 KB Output is correct
40 Correct 6 ms 5844 KB Output is correct
41 Correct 5 ms 7124 KB Output is correct
42 Correct 5 ms 7120 KB Output is correct
43 Correct 7 ms 5076 KB Output is correct
44 Correct 4 ms 5076 KB Output is correct
45 Correct 10 ms 7636 KB Output is correct
46 Correct 6 ms 7764 KB Output is correct
47 Correct 5 ms 5812 KB Output is correct
48 Correct 4 ms 5804 KB Output is correct
49 Correct 8 ms 7112 KB Output is correct
50 Correct 6 ms 7124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5204 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 3 ms 5204 KB Output is correct
6 Correct 3 ms 5204 KB Output is correct
7 Correct 2 ms 5076 KB Output is correct
8 Correct 2 ms 5076 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 4 ms 5128 KB Output is correct
11 Correct 4 ms 5084 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 2 ms 5076 KB Output is correct
16 Correct 2 ms 5016 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 3 ms 5044 KB Output is correct
19 Correct 4 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5076 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 2 ms 5076 KB Output is correct
24 Correct 2 ms 5076 KB Output is correct
25 Correct 57 ms 9792 KB Output is correct
26 Correct 56 ms 9724 KB Output is correct
27 Correct 80 ms 11260 KB Output is correct
28 Correct 78 ms 11340 KB Output is correct
29 Correct 42 ms 11212 KB Output is correct
30 Correct 42 ms 11164 KB Output is correct
31 Correct 7 ms 6612 KB Output is correct
32 Correct 7 ms 6612 KB Output is correct
33 Correct 8 ms 6576 KB Output is correct
34 Correct 7 ms 6592 KB Output is correct
35 Correct 57 ms 7308 KB Output is correct
36 Correct 59 ms 7420 KB Output is correct
37 Correct 71 ms 8764 KB Output is correct
38 Correct 73 ms 9084 KB Output is correct
39 Correct 46 ms 8864 KB Output is correct
40 Correct 41 ms 8608 KB Output is correct
41 Correct 9 ms 6484 KB Output is correct
42 Correct 7 ms 6356 KB Output is correct
43 Correct 57 ms 7116 KB Output is correct
44 Correct 71 ms 7132 KB Output is correct
45 Correct 77 ms 8652 KB Output is correct
46 Correct 69 ms 8628 KB Output is correct
47 Correct 42 ms 8464 KB Output is correct
48 Correct 41 ms 8364 KB Output is correct
49 Correct 8 ms 6312 KB Output is correct
50 Correct 8 ms 6228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5204 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 3 ms 5204 KB Output is correct
6 Correct 3 ms 5204 KB Output is correct
7 Correct 2 ms 5076 KB Output is correct
8 Correct 2 ms 5076 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 4 ms 5128 KB Output is correct
11 Correct 4 ms 5084 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 2 ms 5076 KB Output is correct
16 Correct 2 ms 5016 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 3 ms 5044 KB Output is correct
19 Correct 4 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5076 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 2 ms 5076 KB Output is correct
24 Correct 2 ms 5076 KB Output is correct
25 Correct 57 ms 9792 KB Output is correct
26 Correct 56 ms 9724 KB Output is correct
27 Correct 80 ms 11260 KB Output is correct
28 Correct 78 ms 11340 KB Output is correct
29 Correct 42 ms 11212 KB Output is correct
30 Correct 42 ms 11164 KB Output is correct
31 Correct 7 ms 6612 KB Output is correct
32 Correct 7 ms 6612 KB Output is correct
33 Correct 8 ms 6576 KB Output is correct
34 Correct 7 ms 6592 KB Output is correct
35 Correct 57 ms 7308 KB Output is correct
36 Correct 59 ms 7420 KB Output is correct
37 Correct 71 ms 8764 KB Output is correct
38 Correct 73 ms 9084 KB Output is correct
39 Correct 46 ms 8864 KB Output is correct
40 Correct 41 ms 8608 KB Output is correct
41 Correct 9 ms 6484 KB Output is correct
42 Correct 7 ms 6356 KB Output is correct
43 Correct 57 ms 7116 KB Output is correct
44 Correct 71 ms 7132 KB Output is correct
45 Correct 77 ms 8652 KB Output is correct
46 Correct 69 ms 8628 KB Output is correct
47 Correct 42 ms 8464 KB Output is correct
48 Correct 41 ms 8364 KB Output is correct
49 Correct 8 ms 6312 KB Output is correct
50 Correct 8 ms 6228 KB Output is correct
51 Correct 148 ms 17044 KB Output is correct
52 Correct 163 ms 17100 KB Output is correct
53 Correct 221 ms 21048 KB Output is correct
54 Correct 201 ms 20808 KB Output is correct
55 Correct 125 ms 20648 KB Output is correct
56 Correct 109 ms 20620 KB Output is correct
57 Correct 23 ms 10496 KB Output is correct
58 Correct 23 ms 10396 KB Output is correct
59 Correct 23 ms 10396 KB Output is correct
60 Correct 23 ms 10452 KB Output is correct
61 Correct 148 ms 11040 KB Output is correct
62 Correct 153 ms 11196 KB Output is correct
63 Correct 234 ms 14736 KB Output is correct
64 Correct 198 ms 14820 KB Output is correct
65 Correct 110 ms 14592 KB Output is correct
66 Correct 114 ms 14392 KB Output is correct
67 Correct 23 ms 9148 KB Output is correct
68 Correct 25 ms 9292 KB Output is correct
69 Correct 159 ms 10204 KB Output is correct
70 Correct 153 ms 10184 KB Output is correct
71 Correct 194 ms 14016 KB Output is correct
72 Correct 199 ms 14028 KB Output is correct
73 Correct 108 ms 13644 KB Output is correct
74 Correct 119 ms 13588 KB Output is correct
75 Correct 25 ms 9012 KB Output is correct
76 Correct 26 ms 9092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5204 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 3 ms 5204 KB Output is correct
6 Correct 3 ms 5204 KB Output is correct
7 Correct 2 ms 5076 KB Output is correct
8 Correct 2 ms 5076 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 4 ms 5128 KB Output is correct
11 Correct 4 ms 5084 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 3 ms 5076 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 2 ms 5076 KB Output is correct
16 Correct 2 ms 5016 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 3 ms 5044 KB Output is correct
19 Correct 4 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5076 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 2 ms 5076 KB Output is correct
24 Correct 2 ms 5076 KB Output is correct
25 Correct 4 ms 5076 KB Output is correct
26 Correct 4 ms 5204 KB Output is correct
27 Correct 7 ms 7892 KB Output is correct
28 Correct 8 ms 7892 KB Output is correct
29 Correct 5 ms 5972 KB Output is correct
30 Correct 4 ms 5972 KB Output is correct
31 Correct 6 ms 7224 KB Output is correct
32 Correct 6 ms 7252 KB Output is correct
33 Correct 8 ms 7252 KB Output is correct
34 Correct 5 ms 7252 KB Output is correct
35 Correct 7 ms 5168 KB Output is correct
36 Correct 5 ms 5076 KB Output is correct
37 Correct 10 ms 7732 KB Output is correct
38 Correct 7 ms 7764 KB Output is correct
39 Correct 4 ms 5936 KB Output is correct
40 Correct 6 ms 5844 KB Output is correct
41 Correct 5 ms 7124 KB Output is correct
42 Correct 5 ms 7120 KB Output is correct
43 Correct 7 ms 5076 KB Output is correct
44 Correct 4 ms 5076 KB Output is correct
45 Correct 10 ms 7636 KB Output is correct
46 Correct 6 ms 7764 KB Output is correct
47 Correct 5 ms 5812 KB Output is correct
48 Correct 4 ms 5804 KB Output is correct
49 Correct 8 ms 7112 KB Output is correct
50 Correct 6 ms 7124 KB Output is correct
51 Correct 57 ms 9792 KB Output is correct
52 Correct 56 ms 9724 KB Output is correct
53 Correct 80 ms 11260 KB Output is correct
54 Correct 78 ms 11340 KB Output is correct
55 Correct 42 ms 11212 KB Output is correct
56 Correct 42 ms 11164 KB Output is correct
57 Correct 7 ms 6612 KB Output is correct
58 Correct 7 ms 6612 KB Output is correct
59 Correct 8 ms 6576 KB Output is correct
60 Correct 7 ms 6592 KB Output is correct
61 Correct 57 ms 7308 KB Output is correct
62 Correct 59 ms 7420 KB Output is correct
63 Correct 71 ms 8764 KB Output is correct
64 Correct 73 ms 9084 KB Output is correct
65 Correct 46 ms 8864 KB Output is correct
66 Correct 41 ms 8608 KB Output is correct
67 Correct 9 ms 6484 KB Output is correct
68 Correct 7 ms 6356 KB Output is correct
69 Correct 57 ms 7116 KB Output is correct
70 Correct 71 ms 7132 KB Output is correct
71 Correct 77 ms 8652 KB Output is correct
72 Correct 69 ms 8628 KB Output is correct
73 Correct 42 ms 8464 KB Output is correct
74 Correct 41 ms 8364 KB Output is correct
75 Correct 8 ms 6312 KB Output is correct
76 Correct 8 ms 6228 KB Output is correct
77 Correct 148 ms 17044 KB Output is correct
78 Correct 163 ms 17100 KB Output is correct
79 Correct 221 ms 21048 KB Output is correct
80 Correct 201 ms 20808 KB Output is correct
81 Correct 125 ms 20648 KB Output is correct
82 Correct 109 ms 20620 KB Output is correct
83 Correct 23 ms 10496 KB Output is correct
84 Correct 23 ms 10396 KB Output is correct
85 Correct 23 ms 10396 KB Output is correct
86 Correct 23 ms 10452 KB Output is correct
87 Correct 148 ms 11040 KB Output is correct
88 Correct 153 ms 11196 KB Output is correct
89 Correct 234 ms 14736 KB Output is correct
90 Correct 198 ms 14820 KB Output is correct
91 Correct 110 ms 14592 KB Output is correct
92 Correct 114 ms 14392 KB Output is correct
93 Correct 23 ms 9148 KB Output is correct
94 Correct 25 ms 9292 KB Output is correct
95 Correct 159 ms 10204 KB Output is correct
96 Correct 153 ms 10184 KB Output is correct
97 Correct 194 ms 14016 KB Output is correct
98 Correct 199 ms 14028 KB Output is correct
99 Correct 108 ms 13644 KB Output is correct
100 Correct 119 ms 13588 KB Output is correct
101 Correct 25 ms 9012 KB Output is correct
102 Correct 26 ms 9092 KB Output is correct
103 Correct 227 ms 19920 KB Output is correct
104 Correct 227 ms 19888 KB Output is correct
105 Runtime error 253 ms 185020 KB Execution killed with signal 11
106 Halted 0 ms 0 KB -