Submission #813031

# Submission time Handle Problem Language Result Execution time Memory
813031 2023-08-07T12:48:03 Z stefanopulos Vinjete (COI22_vinjete) C++17
56 / 100
185 ms 20852 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 mn[4 * mxN];
int cnt[4 * mxN];
int lenj[4 * mxN];
void build(int v, int tl, int tr){
    if(tl == tr){
        mn[v] = 0; cnt[v] = 1;
        return; 
    }
    int mid = (tl + tr) / 2;
    build(v * 2, tl, mid); build(v * 2 + 1, mid + 1, tr);
    mn[v] = min(mn[v * 2], mn[v * 2 + 1]);
    cnt[v] = (mn[v] == mn[v * 2] ? cnt[v * 2] : 0) 
    + (mn[v] == mn[v * 2 + 1] ? cnt[v * 2 + 1] : 0);
}

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

void lazyupd(int v, int tl, int tr, int l, int r, int val){
    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(v * 2, tl, mid, l, r, val); lazyupd(v * 2 + 1, mid + 1, tr, l, r, val);
    mn[v] = min(mn[v * 2], mn[v * 2 + 1]);
    cnt[v] = (mn[v] == mn[v * 2] ? cnt[v * 2] : 0) 
    + (mn[v] == mn[v * 2 + 1] ? cnt[v * 2 + 1] : 0);
}

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

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

    build(1,1,m); dfs(1, -1);

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

    return 0;
}
/*



// 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 4 ms 5204 KB Output is correct
4 Correct 4 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 2 ms 5076 KB Output is correct
8 Correct 2 ms 5036 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 4 ms 5076 KB Output is correct
11 Correct 4 ms 5048 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 3 ms 5104 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 2 ms 5076 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 4 ms 5076 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5044 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 2 ms 5076 KB Output is correct
24 Correct 3 ms 5032 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 4 ms 5204 KB Output is correct
4 Correct 4 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 2 ms 5076 KB Output is correct
8 Correct 2 ms 5036 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 4 ms 5076 KB Output is correct
11 Correct 4 ms 5048 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 3 ms 5104 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 2 ms 5076 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 4 ms 5076 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5044 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 2 ms 5076 KB Output is correct
24 Correct 3 ms 5032 KB Output is correct
25 Runtime error 6 ms 10068 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -
# 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 4 ms 5204 KB Output is correct
4 Correct 4 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 2 ms 5076 KB Output is correct
8 Correct 2 ms 5036 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 4 ms 5076 KB Output is correct
11 Correct 4 ms 5048 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 3 ms 5104 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 2 ms 5076 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 4 ms 5076 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5044 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 2 ms 5076 KB Output is correct
24 Correct 3 ms 5032 KB Output is correct
25 Correct 50 ms 10956 KB Output is correct
26 Correct 49 ms 10988 KB Output is correct
27 Correct 62 ms 11632 KB Output is correct
28 Correct 65 ms 11564 KB Output is correct
29 Correct 40 ms 11428 KB Output is correct
30 Correct 40 ms 11424 KB Output is correct
31 Correct 8 ms 7088 KB Output is correct
32 Correct 7 ms 7124 KB Output is correct
33 Correct 7 ms 7124 KB Output is correct
34 Correct 7 ms 7124 KB Output is correct
35 Correct 49 ms 9016 KB Output is correct
36 Correct 53 ms 9140 KB Output is correct
37 Correct 80 ms 9608 KB Output is correct
38 Correct 64 ms 9768 KB Output is correct
39 Correct 41 ms 9568 KB Output is correct
40 Correct 38 ms 9444 KB Output is correct
41 Correct 7 ms 6868 KB Output is correct
42 Correct 8 ms 6868 KB Output is correct
43 Correct 61 ms 8876 KB Output is correct
44 Correct 51 ms 8952 KB Output is correct
45 Correct 65 ms 9460 KB Output is correct
46 Correct 61 ms 9480 KB Output is correct
47 Correct 39 ms 9240 KB Output is correct
48 Correct 39 ms 9208 KB Output is correct
49 Correct 8 ms 6868 KB Output is correct
50 Correct 8 ms 6904 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 4 ms 5204 KB Output is correct
4 Correct 4 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 2 ms 5076 KB Output is correct
8 Correct 2 ms 5036 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 4 ms 5076 KB Output is correct
11 Correct 4 ms 5048 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 3 ms 5104 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 2 ms 5076 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 4 ms 5076 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5044 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 2 ms 5076 KB Output is correct
24 Correct 3 ms 5032 KB Output is correct
25 Correct 50 ms 10956 KB Output is correct
26 Correct 49 ms 10988 KB Output is correct
27 Correct 62 ms 11632 KB Output is correct
28 Correct 65 ms 11564 KB Output is correct
29 Correct 40 ms 11428 KB Output is correct
30 Correct 40 ms 11424 KB Output is correct
31 Correct 8 ms 7088 KB Output is correct
32 Correct 7 ms 7124 KB Output is correct
33 Correct 7 ms 7124 KB Output is correct
34 Correct 7 ms 7124 KB Output is correct
35 Correct 49 ms 9016 KB Output is correct
36 Correct 53 ms 9140 KB Output is correct
37 Correct 80 ms 9608 KB Output is correct
38 Correct 64 ms 9768 KB Output is correct
39 Correct 41 ms 9568 KB Output is correct
40 Correct 38 ms 9444 KB Output is correct
41 Correct 7 ms 6868 KB Output is correct
42 Correct 8 ms 6868 KB Output is correct
43 Correct 61 ms 8876 KB Output is correct
44 Correct 51 ms 8952 KB Output is correct
45 Correct 65 ms 9460 KB Output is correct
46 Correct 61 ms 9480 KB Output is correct
47 Correct 39 ms 9240 KB Output is correct
48 Correct 39 ms 9208 KB Output is correct
49 Correct 8 ms 6868 KB Output is correct
50 Correct 8 ms 6904 KB Output is correct
51 Correct 126 ms 19608 KB Output is correct
52 Correct 127 ms 19524 KB Output is correct
53 Correct 161 ms 20852 KB Output is correct
54 Correct 174 ms 20840 KB Output is correct
55 Correct 98 ms 20504 KB Output is correct
56 Correct 96 ms 20428 KB Output is correct
57 Correct 22 ms 10576 KB Output is correct
58 Correct 22 ms 10540 KB Output is correct
59 Correct 22 ms 10544 KB Output is correct
60 Correct 22 ms 10508 KB Output is correct
61 Correct 140 ms 15056 KB Output is correct
62 Correct 131 ms 15120 KB Output is correct
63 Correct 185 ms 15984 KB Output is correct
64 Correct 168 ms 16076 KB Output is correct
65 Correct 130 ms 15932 KB Output is correct
66 Correct 102 ms 15692 KB Output is correct
67 Correct 25 ms 9568 KB Output is correct
68 Correct 23 ms 9496 KB Output is correct
69 Correct 135 ms 14292 KB Output is correct
70 Correct 144 ms 14300 KB Output is correct
71 Correct 169 ms 15660 KB Output is correct
72 Correct 170 ms 15568 KB Output is correct
73 Correct 111 ms 14984 KB Output is correct
74 Correct 98 ms 15052 KB Output is correct
75 Correct 24 ms 9428 KB Output is correct
76 Correct 24 ms 9384 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 4 ms 5204 KB Output is correct
4 Correct 4 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 2 ms 5076 KB Output is correct
8 Correct 2 ms 5036 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 4 ms 5076 KB Output is correct
11 Correct 4 ms 5048 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 3 ms 5104 KB Output is correct
14 Correct 3 ms 5076 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 2 ms 5076 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 4 ms 5076 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5044 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 2 ms 5076 KB Output is correct
24 Correct 3 ms 5032 KB Output is correct
25 Runtime error 6 ms 10068 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -