답안 #813103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
813103 2023-08-07T13:31:17 Z stefanopulos Vinjete (COI22_vinjete) C++17
100 / 100
684 ms 188468 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[50 * mxN];
int rs[50 * mxN];
int mn[50 * mxN];
int cnt[50 * mxN];
int lenj[50 * 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
*/
 
 
 
 
 
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5200 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5204 KB Output is correct
4 Correct 3 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 4 ms 5076 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 4 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 5076 KB Output is correct
17 Correct 4 ms 5104 KB Output is correct
18 Correct 3 ms 5052 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 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
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5200 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5204 KB Output is correct
4 Correct 3 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 4 ms 5076 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 4 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 5076 KB Output is correct
17 Correct 4 ms 5104 KB Output is correct
18 Correct 3 ms 5052 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 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 5 ms 5204 KB Output is correct
26 Correct 5 ms 5076 KB Output is correct
27 Correct 6 ms 7848 KB Output is correct
28 Correct 6 ms 7892 KB Output is correct
29 Correct 4 ms 5844 KB Output is correct
30 Correct 4 ms 5844 KB Output is correct
31 Correct 5 ms 7124 KB Output is correct
32 Correct 5 ms 7260 KB Output is correct
33 Correct 6 ms 7252 KB Output is correct
34 Correct 5 ms 7252 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 4 ms 5076 KB Output is correct
37 Correct 7 ms 7764 KB Output is correct
38 Correct 7 ms 7764 KB Output is correct
39 Correct 4 ms 5844 KB Output is correct
40 Correct 4 ms 5828 KB Output is correct
41 Correct 5 ms 7124 KB Output is correct
42 Correct 5 ms 7124 KB Output is correct
43 Correct 5 ms 5076 KB Output is correct
44 Correct 5 ms 5132 KB Output is correct
45 Correct 6 ms 7636 KB Output is correct
46 Correct 6 ms 7636 KB Output is correct
47 Correct 4 ms 5844 KB Output is correct
48 Correct 4 ms 5872 KB Output is correct
49 Correct 5 ms 7124 KB Output is correct
50 Correct 5 ms 7124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5200 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5204 KB Output is correct
4 Correct 3 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 4 ms 5076 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 4 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 5076 KB Output is correct
17 Correct 4 ms 5104 KB Output is correct
18 Correct 3 ms 5052 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 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 62 ms 9732 KB Output is correct
26 Correct 57 ms 9716 KB Output is correct
27 Correct 76 ms 11256 KB Output is correct
28 Correct 73 ms 11252 KB Output is correct
29 Correct 41 ms 11160 KB Output is correct
30 Correct 42 ms 11272 KB Output is correct
31 Correct 7 ms 6644 KB Output is correct
32 Correct 7 ms 6612 KB Output is correct
33 Correct 7 ms 6652 KB Output is correct
34 Correct 8 ms 6648 KB Output is correct
35 Correct 54 ms 7324 KB Output is correct
36 Correct 65 ms 7376 KB Output is correct
37 Correct 72 ms 8776 KB Output is correct
38 Correct 72 ms 9036 KB Output is correct
39 Correct 41 ms 8752 KB Output is correct
40 Correct 43 ms 8652 KB Output is correct
41 Correct 7 ms 6356 KB Output is correct
42 Correct 7 ms 6356 KB Output is correct
43 Correct 57 ms 7052 KB Output is correct
44 Correct 71 ms 7168 KB Output is correct
45 Correct 70 ms 8600 KB Output is correct
46 Correct 70 ms 8568 KB Output is correct
47 Correct 44 ms 8400 KB Output is correct
48 Correct 41 ms 8444 KB Output is correct
49 Correct 8 ms 6228 KB Output is correct
50 Correct 8 ms 6324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5200 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5204 KB Output is correct
4 Correct 3 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 4 ms 5076 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 4 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 5076 KB Output is correct
17 Correct 4 ms 5104 KB Output is correct
18 Correct 3 ms 5052 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 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 62 ms 9732 KB Output is correct
26 Correct 57 ms 9716 KB Output is correct
27 Correct 76 ms 11256 KB Output is correct
28 Correct 73 ms 11252 KB Output is correct
29 Correct 41 ms 11160 KB Output is correct
30 Correct 42 ms 11272 KB Output is correct
31 Correct 7 ms 6644 KB Output is correct
32 Correct 7 ms 6612 KB Output is correct
33 Correct 7 ms 6652 KB Output is correct
34 Correct 8 ms 6648 KB Output is correct
35 Correct 54 ms 7324 KB Output is correct
36 Correct 65 ms 7376 KB Output is correct
37 Correct 72 ms 8776 KB Output is correct
38 Correct 72 ms 9036 KB Output is correct
39 Correct 41 ms 8752 KB Output is correct
40 Correct 43 ms 8652 KB Output is correct
41 Correct 7 ms 6356 KB Output is correct
42 Correct 7 ms 6356 KB Output is correct
43 Correct 57 ms 7052 KB Output is correct
44 Correct 71 ms 7168 KB Output is correct
45 Correct 70 ms 8600 KB Output is correct
46 Correct 70 ms 8568 KB Output is correct
47 Correct 44 ms 8400 KB Output is correct
48 Correct 41 ms 8444 KB Output is correct
49 Correct 8 ms 6228 KB Output is correct
50 Correct 8 ms 6324 KB Output is correct
51 Correct 147 ms 17044 KB Output is correct
52 Correct 147 ms 17096 KB Output is correct
53 Correct 196 ms 20924 KB Output is correct
54 Correct 194 ms 20804 KB Output is correct
55 Correct 107 ms 20584 KB Output is correct
56 Correct 115 ms 20552 KB Output is correct
57 Correct 24 ms 10420 KB Output is correct
58 Correct 23 ms 10464 KB Output is correct
59 Correct 23 ms 10452 KB Output is correct
60 Correct 23 ms 10364 KB Output is correct
61 Correct 144 ms 10992 KB Output is correct
62 Correct 154 ms 11232 KB Output is correct
63 Correct 195 ms 14584 KB Output is correct
64 Correct 191 ms 14704 KB Output is correct
65 Correct 122 ms 14692 KB Output is correct
66 Correct 119 ms 14388 KB Output is correct
67 Correct 23 ms 9148 KB Output is correct
68 Correct 23 ms 9212 KB Output is correct
69 Correct 150 ms 10204 KB Output is correct
70 Correct 159 ms 10216 KB Output is correct
71 Correct 185 ms 14016 KB Output is correct
72 Correct 195 ms 14000 KB Output is correct
73 Correct 107 ms 13572 KB Output is correct
74 Correct 127 ms 13544 KB Output is correct
75 Correct 31 ms 9044 KB Output is correct
76 Correct 26 ms 9088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5200 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5204 KB Output is correct
4 Correct 3 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 4 ms 5076 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 4 ms 5076 KB Output is correct
12 Correct 4 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 5076 KB Output is correct
17 Correct 4 ms 5104 KB Output is correct
18 Correct 3 ms 5052 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 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 5 ms 5204 KB Output is correct
26 Correct 5 ms 5076 KB Output is correct
27 Correct 6 ms 7848 KB Output is correct
28 Correct 6 ms 7892 KB Output is correct
29 Correct 4 ms 5844 KB Output is correct
30 Correct 4 ms 5844 KB Output is correct
31 Correct 5 ms 7124 KB Output is correct
32 Correct 5 ms 7260 KB Output is correct
33 Correct 6 ms 7252 KB Output is correct
34 Correct 5 ms 7252 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 4 ms 5076 KB Output is correct
37 Correct 7 ms 7764 KB Output is correct
38 Correct 7 ms 7764 KB Output is correct
39 Correct 4 ms 5844 KB Output is correct
40 Correct 4 ms 5828 KB Output is correct
41 Correct 5 ms 7124 KB Output is correct
42 Correct 5 ms 7124 KB Output is correct
43 Correct 5 ms 5076 KB Output is correct
44 Correct 5 ms 5132 KB Output is correct
45 Correct 6 ms 7636 KB Output is correct
46 Correct 6 ms 7636 KB Output is correct
47 Correct 4 ms 5844 KB Output is correct
48 Correct 4 ms 5872 KB Output is correct
49 Correct 5 ms 7124 KB Output is correct
50 Correct 5 ms 7124 KB Output is correct
51 Correct 62 ms 9732 KB Output is correct
52 Correct 57 ms 9716 KB Output is correct
53 Correct 76 ms 11256 KB Output is correct
54 Correct 73 ms 11252 KB Output is correct
55 Correct 41 ms 11160 KB Output is correct
56 Correct 42 ms 11272 KB Output is correct
57 Correct 7 ms 6644 KB Output is correct
58 Correct 7 ms 6612 KB Output is correct
59 Correct 7 ms 6652 KB Output is correct
60 Correct 8 ms 6648 KB Output is correct
61 Correct 54 ms 7324 KB Output is correct
62 Correct 65 ms 7376 KB Output is correct
63 Correct 72 ms 8776 KB Output is correct
64 Correct 72 ms 9036 KB Output is correct
65 Correct 41 ms 8752 KB Output is correct
66 Correct 43 ms 8652 KB Output is correct
67 Correct 7 ms 6356 KB Output is correct
68 Correct 7 ms 6356 KB Output is correct
69 Correct 57 ms 7052 KB Output is correct
70 Correct 71 ms 7168 KB Output is correct
71 Correct 70 ms 8600 KB Output is correct
72 Correct 70 ms 8568 KB Output is correct
73 Correct 44 ms 8400 KB Output is correct
74 Correct 41 ms 8444 KB Output is correct
75 Correct 8 ms 6228 KB Output is correct
76 Correct 8 ms 6324 KB Output is correct
77 Correct 147 ms 17044 KB Output is correct
78 Correct 147 ms 17096 KB Output is correct
79 Correct 196 ms 20924 KB Output is correct
80 Correct 194 ms 20804 KB Output is correct
81 Correct 107 ms 20584 KB Output is correct
82 Correct 115 ms 20552 KB Output is correct
83 Correct 24 ms 10420 KB Output is correct
84 Correct 23 ms 10464 KB Output is correct
85 Correct 23 ms 10452 KB Output is correct
86 Correct 23 ms 10364 KB Output is correct
87 Correct 144 ms 10992 KB Output is correct
88 Correct 154 ms 11232 KB Output is correct
89 Correct 195 ms 14584 KB Output is correct
90 Correct 191 ms 14704 KB Output is correct
91 Correct 122 ms 14692 KB Output is correct
92 Correct 119 ms 14388 KB Output is correct
93 Correct 23 ms 9148 KB Output is correct
94 Correct 23 ms 9212 KB Output is correct
95 Correct 150 ms 10204 KB Output is correct
96 Correct 159 ms 10216 KB Output is correct
97 Correct 185 ms 14016 KB Output is correct
98 Correct 195 ms 14000 KB Output is correct
99 Correct 107 ms 13572 KB Output is correct
100 Correct 127 ms 13544 KB Output is correct
101 Correct 31 ms 9044 KB Output is correct
102 Correct 26 ms 9088 KB Output is correct
103 Correct 228 ms 17460 KB Output is correct
104 Correct 229 ms 17500 KB Output is correct
105 Correct 670 ms 185564 KB Output is correct
106 Correct 684 ms 188468 KB Output is correct
107 Correct 291 ms 72520 KB Output is correct
108 Correct 268 ms 72604 KB Output is correct
109 Correct 65 ms 39516 KB Output is correct
110 Correct 64 ms 39492 KB Output is correct
111 Correct 63 ms 39496 KB Output is correct
112 Correct 64 ms 39504 KB Output is correct
113 Correct 227 ms 14168 KB Output is correct
114 Correct 235 ms 13976 KB Output is correct
115 Correct 595 ms 182552 KB Output is correct
116 Correct 626 ms 182768 KB Output is correct
117 Correct 258 ms 66516 KB Output is correct
118 Correct 267 ms 66296 KB Output is correct
119 Correct 85 ms 38388 KB Output is correct
120 Correct 95 ms 38328 KB Output is correct
121 Correct 272 ms 13004 KB Output is correct
122 Correct 286 ms 13008 KB Output is correct
123 Correct 622 ms 179732 KB Output is correct
124 Correct 617 ms 181156 KB Output is correct
125 Correct 253 ms 65556 KB Output is correct
126 Correct 249 ms 65484 KB Output is correct
127 Correct 68 ms 38232 KB Output is correct
128 Correct 80 ms 38032 KB Output is correct