Submission #864017

# Submission time Handle Problem Language Result Execution time Memory
864017 2023-10-21T17:02:21 Z serifefedartar Vinjete (COI22_vinjete) C++17
100 / 100
270 ms 36656 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll LOGN = 20; 
const ll MAXN = 1e5 + 5;

struct Edge {
	int to, l, r;
	Edge(int _to, int _l, int _r) : to(_to), l(_l), r(_r) { }
};

struct Node {
	int len;
	int mn, mn_cnt;
	Node() : len(0), mn(1e9), mn_cnt(0) { }
};

vector<vector<Edge>> graph;
vector<int> cc;
Node sg[12*MAXN];
int lazy[12*MAXN], ans[MAXN];

int n, M;
Node merge(Node a, Node b) {
	Node temp;
	temp.len = a.len + b.len;
	temp.mn = min(a.mn, b.mn);
	temp.mn_cnt = (temp.mn == a.mn ? a.mn_cnt : 0) + (temp.mn == b.mn ? b.mn_cnt : 0);
	return temp;
}

void push(int k, int a, int b) {
	if (lazy[k]) {
		sg[k].mn += lazy[k];
		if (a != b) {
			lazy[2*k] += lazy[k];
			lazy[2*k+1] += lazy[k];
		}
		lazy[k] = 0;
	}
}

void init(int k, int a, int b) {
	if (a == b) {
		sg[k].mn_cnt = sg[k].len = (a == n ? 0 : cc[a] - cc[a-1]);
		sg[k].mn = 0;
		return ;
	}
	init(2*k, a, (a+b)/2);
	init(2*k+1, (a+b)/2+1, b);
	sg[k] = merge(sg[2*k], sg[2*k+1]);
}

void update(int k, int a, int b, int q_l, int q_r, int val) {
	push(k, a, b);
	if (b < q_l || a > q_r)
		return ;
	if (q_l <= a && b <= q_r) {
		lazy[k] += val;
		push(k, a, b);
		return ;
	}
	update(2*k, a, (a+b)/2, q_l, q_r, val);
	update(2*k+1, (a+b)/2+1, b, q_l, q_r, val);
	sg[k] = merge(sg[2*k], sg[2*k+1]);
}
	
Node emp;
Node query(int k, int a, int b, int q_l, int q_r) {
	push(k, a, b);
	if (b < q_l || a > q_r)
		return emp;
	if (q_l <= a && b <= q_r)
		return sg[k];

	return merge(query(2*k, a, (a+b)/2, q_l, q_r), query(2*k+1, (a+b)/2+1, b, q_l, q_r));
}

int index(int k) {
	return upper_bound(cc.begin(), cc.end(), k) - cc.begin();
}

void dfs(int node, int parent) {
	push(1, 1, n);
	if (sg[1].mn == 0)
		ans[node] = cc[n-2] - sg[1].mn_cnt;

	for (auto u : graph[node]) {
		if (u.to == parent)
			continue;
		int left = index(u.l); 
		int right = index(u.r);
		update(1, 1, n, left, right, 1);
		dfs(u.to, node);
		update(1, 1, n, left, right, -1);
	}
}

int main() {
	fast
	int N, a, b, l, r;
	cin >> N >> M;

	graph = vector<vector<Edge>>(N+1, vector<Edge>());
	for (int i = 1; i < N; i++) {
		cin >> a >> b >> l >> r;
		graph[a].push_back(Edge(b, l, r));
		graph[b].push_back(Edge(a, l, r));
		cc.push_back(l);
		cc.push_back(r);
		cc.push_back(r+1);
	}
	cc.push_back(1);
	sort(cc.begin(), cc.end());
	cc.erase(unique(cc.begin(), cc.end()), cc.end());
	n = cc.size();
	init(1, 1, n);
	dfs(1, 1);

	for (int i = 2; i <= N; i++)
		cout << ans[i] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 15608 KB Output is correct
2 Correct 4 ms 15448 KB Output is correct
3 Correct 4 ms 15448 KB Output is correct
4 Correct 4 ms 15452 KB Output is correct
5 Correct 4 ms 15484 KB Output is correct
6 Correct 4 ms 15452 KB Output is correct
7 Correct 4 ms 15552 KB Output is correct
8 Correct 3 ms 15196 KB Output is correct
9 Correct 4 ms 15452 KB Output is correct
10 Correct 4 ms 15452 KB Output is correct
11 Correct 5 ms 15476 KB Output is correct
12 Correct 4 ms 15452 KB Output is correct
13 Correct 4 ms 15452 KB Output is correct
14 Correct 4 ms 15452 KB Output is correct
15 Correct 3 ms 15196 KB Output is correct
16 Correct 3 ms 15296 KB Output is correct
17 Correct 4 ms 15452 KB Output is correct
18 Correct 4 ms 15452 KB Output is correct
19 Correct 4 ms 15448 KB Output is correct
20 Correct 4 ms 15452 KB Output is correct
21 Correct 4 ms 15452 KB Output is correct
22 Correct 4 ms 15452 KB Output is correct
23 Correct 3 ms 15292 KB Output is correct
24 Correct 4 ms 15196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 15608 KB Output is correct
2 Correct 4 ms 15448 KB Output is correct
3 Correct 4 ms 15448 KB Output is correct
4 Correct 4 ms 15452 KB Output is correct
5 Correct 4 ms 15484 KB Output is correct
6 Correct 4 ms 15452 KB Output is correct
7 Correct 4 ms 15552 KB Output is correct
8 Correct 3 ms 15196 KB Output is correct
9 Correct 4 ms 15452 KB Output is correct
10 Correct 4 ms 15452 KB Output is correct
11 Correct 5 ms 15476 KB Output is correct
12 Correct 4 ms 15452 KB Output is correct
13 Correct 4 ms 15452 KB Output is correct
14 Correct 4 ms 15452 KB Output is correct
15 Correct 3 ms 15196 KB Output is correct
16 Correct 3 ms 15296 KB Output is correct
17 Correct 4 ms 15452 KB Output is correct
18 Correct 4 ms 15452 KB Output is correct
19 Correct 4 ms 15448 KB Output is correct
20 Correct 4 ms 15452 KB Output is correct
21 Correct 4 ms 15452 KB Output is correct
22 Correct 4 ms 15452 KB Output is correct
23 Correct 3 ms 15292 KB Output is correct
24 Correct 4 ms 15196 KB Output is correct
25 Correct 4 ms 15452 KB Output is correct
26 Correct 4 ms 15452 KB Output is correct
27 Correct 5 ms 15452 KB Output is correct
28 Correct 5 ms 15452 KB Output is correct
29 Correct 4 ms 15452 KB Output is correct
30 Correct 4 ms 15376 KB Output is correct
31 Correct 4 ms 15452 KB Output is correct
32 Correct 4 ms 15564 KB Output is correct
33 Correct 4 ms 15452 KB Output is correct
34 Correct 4 ms 15332 KB Output is correct
35 Correct 5 ms 15448 KB Output is correct
36 Correct 4 ms 15448 KB Output is correct
37 Correct 5 ms 15452 KB Output is correct
38 Correct 5 ms 15368 KB Output is correct
39 Correct 4 ms 15452 KB Output is correct
40 Correct 4 ms 15452 KB Output is correct
41 Correct 4 ms 15448 KB Output is correct
42 Correct 5 ms 15452 KB Output is correct
43 Correct 4 ms 15452 KB Output is correct
44 Correct 4 ms 15452 KB Output is correct
45 Correct 4 ms 15452 KB Output is correct
46 Correct 5 ms 15452 KB Output is correct
47 Correct 4 ms 15304 KB Output is correct
48 Correct 4 ms 15452 KB Output is correct
49 Correct 4 ms 15380 KB Output is correct
50 Correct 4 ms 15452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 15608 KB Output is correct
2 Correct 4 ms 15448 KB Output is correct
3 Correct 4 ms 15448 KB Output is correct
4 Correct 4 ms 15452 KB Output is correct
5 Correct 4 ms 15484 KB Output is correct
6 Correct 4 ms 15452 KB Output is correct
7 Correct 4 ms 15552 KB Output is correct
8 Correct 3 ms 15196 KB Output is correct
9 Correct 4 ms 15452 KB Output is correct
10 Correct 4 ms 15452 KB Output is correct
11 Correct 5 ms 15476 KB Output is correct
12 Correct 4 ms 15452 KB Output is correct
13 Correct 4 ms 15452 KB Output is correct
14 Correct 4 ms 15452 KB Output is correct
15 Correct 3 ms 15196 KB Output is correct
16 Correct 3 ms 15296 KB Output is correct
17 Correct 4 ms 15452 KB Output is correct
18 Correct 4 ms 15452 KB Output is correct
19 Correct 4 ms 15448 KB Output is correct
20 Correct 4 ms 15452 KB Output is correct
21 Correct 4 ms 15452 KB Output is correct
22 Correct 4 ms 15452 KB Output is correct
23 Correct 3 ms 15292 KB Output is correct
24 Correct 4 ms 15196 KB Output is correct
25 Correct 53 ms 21708 KB Output is correct
26 Correct 44 ms 21720 KB Output is correct
27 Correct 80 ms 22232 KB Output is correct
28 Correct 78 ms 22216 KB Output is correct
29 Correct 52 ms 21972 KB Output is correct
30 Correct 52 ms 21960 KB Output is correct
31 Correct 9 ms 16216 KB Output is correct
32 Correct 9 ms 16216 KB Output is correct
33 Correct 9 ms 16120 KB Output is correct
34 Correct 9 ms 16220 KB Output is correct
35 Correct 43 ms 19716 KB Output is correct
36 Correct 43 ms 19912 KB Output is correct
37 Correct 95 ms 20188 KB Output is correct
38 Correct 82 ms 20488 KB Output is correct
39 Correct 52 ms 20168 KB Output is correct
40 Correct 52 ms 20172 KB Output is correct
41 Correct 9 ms 15992 KB Output is correct
42 Correct 9 ms 15964 KB Output is correct
43 Correct 50 ms 19460 KB Output is correct
44 Correct 46 ms 19448 KB Output is correct
45 Correct 78 ms 20052 KB Output is correct
46 Correct 77 ms 20172 KB Output is correct
47 Correct 52 ms 19924 KB Output is correct
48 Correct 55 ms 20012 KB Output is correct
49 Correct 9 ms 15964 KB Output is correct
50 Correct 9 ms 15964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 15608 KB Output is correct
2 Correct 4 ms 15448 KB Output is correct
3 Correct 4 ms 15448 KB Output is correct
4 Correct 4 ms 15452 KB Output is correct
5 Correct 4 ms 15484 KB Output is correct
6 Correct 4 ms 15452 KB Output is correct
7 Correct 4 ms 15552 KB Output is correct
8 Correct 3 ms 15196 KB Output is correct
9 Correct 4 ms 15452 KB Output is correct
10 Correct 4 ms 15452 KB Output is correct
11 Correct 5 ms 15476 KB Output is correct
12 Correct 4 ms 15452 KB Output is correct
13 Correct 4 ms 15452 KB Output is correct
14 Correct 4 ms 15452 KB Output is correct
15 Correct 3 ms 15196 KB Output is correct
16 Correct 3 ms 15296 KB Output is correct
17 Correct 4 ms 15452 KB Output is correct
18 Correct 4 ms 15452 KB Output is correct
19 Correct 4 ms 15448 KB Output is correct
20 Correct 4 ms 15452 KB Output is correct
21 Correct 4 ms 15452 KB Output is correct
22 Correct 4 ms 15452 KB Output is correct
23 Correct 3 ms 15292 KB Output is correct
24 Correct 4 ms 15196 KB Output is correct
25 Correct 53 ms 21708 KB Output is correct
26 Correct 44 ms 21720 KB Output is correct
27 Correct 80 ms 22232 KB Output is correct
28 Correct 78 ms 22216 KB Output is correct
29 Correct 52 ms 21972 KB Output is correct
30 Correct 52 ms 21960 KB Output is correct
31 Correct 9 ms 16216 KB Output is correct
32 Correct 9 ms 16216 KB Output is correct
33 Correct 9 ms 16120 KB Output is correct
34 Correct 9 ms 16220 KB Output is correct
35 Correct 43 ms 19716 KB Output is correct
36 Correct 43 ms 19912 KB Output is correct
37 Correct 95 ms 20188 KB Output is correct
38 Correct 82 ms 20488 KB Output is correct
39 Correct 52 ms 20168 KB Output is correct
40 Correct 52 ms 20172 KB Output is correct
41 Correct 9 ms 15992 KB Output is correct
42 Correct 9 ms 15964 KB Output is correct
43 Correct 50 ms 19460 KB Output is correct
44 Correct 46 ms 19448 KB Output is correct
45 Correct 78 ms 20052 KB Output is correct
46 Correct 77 ms 20172 KB Output is correct
47 Correct 52 ms 19924 KB Output is correct
48 Correct 55 ms 20012 KB Output is correct
49 Correct 9 ms 15964 KB Output is correct
50 Correct 9 ms 15964 KB Output is correct
51 Correct 114 ms 31304 KB Output is correct
52 Correct 107 ms 31212 KB Output is correct
53 Correct 206 ms 32692 KB Output is correct
54 Correct 214 ms 32528 KB Output is correct
55 Correct 134 ms 32272 KB Output is correct
56 Correct 139 ms 32292 KB Output is correct
57 Correct 26 ms 18896 KB Output is correct
58 Correct 31 ms 18896 KB Output is correct
59 Correct 27 ms 18804 KB Output is correct
60 Correct 26 ms 18904 KB Output is correct
61 Correct 113 ms 26632 KB Output is correct
62 Correct 105 ms 26752 KB Output is correct
63 Correct 220 ms 27624 KB Output is correct
64 Correct 221 ms 27728 KB Output is correct
65 Correct 144 ms 27588 KB Output is correct
66 Correct 138 ms 27524 KB Output is correct
67 Correct 28 ms 17880 KB Output is correct
68 Correct 27 ms 17844 KB Output is correct
69 Correct 141 ms 26136 KB Output is correct
70 Correct 116 ms 26048 KB Output is correct
71 Correct 221 ms 27376 KB Output is correct
72 Correct 238 ms 27456 KB Output is correct
73 Correct 140 ms 26860 KB Output is correct
74 Correct 138 ms 26816 KB Output is correct
75 Correct 29 ms 17868 KB Output is correct
76 Correct 29 ms 17868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 15608 KB Output is correct
2 Correct 4 ms 15448 KB Output is correct
3 Correct 4 ms 15448 KB Output is correct
4 Correct 4 ms 15452 KB Output is correct
5 Correct 4 ms 15484 KB Output is correct
6 Correct 4 ms 15452 KB Output is correct
7 Correct 4 ms 15552 KB Output is correct
8 Correct 3 ms 15196 KB Output is correct
9 Correct 4 ms 15452 KB Output is correct
10 Correct 4 ms 15452 KB Output is correct
11 Correct 5 ms 15476 KB Output is correct
12 Correct 4 ms 15452 KB Output is correct
13 Correct 4 ms 15452 KB Output is correct
14 Correct 4 ms 15452 KB Output is correct
15 Correct 3 ms 15196 KB Output is correct
16 Correct 3 ms 15296 KB Output is correct
17 Correct 4 ms 15452 KB Output is correct
18 Correct 4 ms 15452 KB Output is correct
19 Correct 4 ms 15448 KB Output is correct
20 Correct 4 ms 15452 KB Output is correct
21 Correct 4 ms 15452 KB Output is correct
22 Correct 4 ms 15452 KB Output is correct
23 Correct 3 ms 15292 KB Output is correct
24 Correct 4 ms 15196 KB Output is correct
25 Correct 4 ms 15452 KB Output is correct
26 Correct 4 ms 15452 KB Output is correct
27 Correct 5 ms 15452 KB Output is correct
28 Correct 5 ms 15452 KB Output is correct
29 Correct 4 ms 15452 KB Output is correct
30 Correct 4 ms 15376 KB Output is correct
31 Correct 4 ms 15452 KB Output is correct
32 Correct 4 ms 15564 KB Output is correct
33 Correct 4 ms 15452 KB Output is correct
34 Correct 4 ms 15332 KB Output is correct
35 Correct 5 ms 15448 KB Output is correct
36 Correct 4 ms 15448 KB Output is correct
37 Correct 5 ms 15452 KB Output is correct
38 Correct 5 ms 15368 KB Output is correct
39 Correct 4 ms 15452 KB Output is correct
40 Correct 4 ms 15452 KB Output is correct
41 Correct 4 ms 15448 KB Output is correct
42 Correct 5 ms 15452 KB Output is correct
43 Correct 4 ms 15452 KB Output is correct
44 Correct 4 ms 15452 KB Output is correct
45 Correct 4 ms 15452 KB Output is correct
46 Correct 5 ms 15452 KB Output is correct
47 Correct 4 ms 15304 KB Output is correct
48 Correct 4 ms 15452 KB Output is correct
49 Correct 4 ms 15380 KB Output is correct
50 Correct 4 ms 15452 KB Output is correct
51 Correct 53 ms 21708 KB Output is correct
52 Correct 44 ms 21720 KB Output is correct
53 Correct 80 ms 22232 KB Output is correct
54 Correct 78 ms 22216 KB Output is correct
55 Correct 52 ms 21972 KB Output is correct
56 Correct 52 ms 21960 KB Output is correct
57 Correct 9 ms 16216 KB Output is correct
58 Correct 9 ms 16216 KB Output is correct
59 Correct 9 ms 16120 KB Output is correct
60 Correct 9 ms 16220 KB Output is correct
61 Correct 43 ms 19716 KB Output is correct
62 Correct 43 ms 19912 KB Output is correct
63 Correct 95 ms 20188 KB Output is correct
64 Correct 82 ms 20488 KB Output is correct
65 Correct 52 ms 20168 KB Output is correct
66 Correct 52 ms 20172 KB Output is correct
67 Correct 9 ms 15992 KB Output is correct
68 Correct 9 ms 15964 KB Output is correct
69 Correct 50 ms 19460 KB Output is correct
70 Correct 46 ms 19448 KB Output is correct
71 Correct 78 ms 20052 KB Output is correct
72 Correct 77 ms 20172 KB Output is correct
73 Correct 52 ms 19924 KB Output is correct
74 Correct 55 ms 20012 KB Output is correct
75 Correct 9 ms 15964 KB Output is correct
76 Correct 9 ms 15964 KB Output is correct
77 Correct 114 ms 31304 KB Output is correct
78 Correct 107 ms 31212 KB Output is correct
79 Correct 206 ms 32692 KB Output is correct
80 Correct 214 ms 32528 KB Output is correct
81 Correct 134 ms 32272 KB Output is correct
82 Correct 139 ms 32292 KB Output is correct
83 Correct 26 ms 18896 KB Output is correct
84 Correct 31 ms 18896 KB Output is correct
85 Correct 27 ms 18804 KB Output is correct
86 Correct 26 ms 18904 KB Output is correct
87 Correct 113 ms 26632 KB Output is correct
88 Correct 105 ms 26752 KB Output is correct
89 Correct 220 ms 27624 KB Output is correct
90 Correct 221 ms 27728 KB Output is correct
91 Correct 144 ms 27588 KB Output is correct
92 Correct 138 ms 27524 KB Output is correct
93 Correct 28 ms 17880 KB Output is correct
94 Correct 27 ms 17844 KB Output is correct
95 Correct 141 ms 26136 KB Output is correct
96 Correct 116 ms 26048 KB Output is correct
97 Correct 221 ms 27376 KB Output is correct
98 Correct 238 ms 27456 KB Output is correct
99 Correct 140 ms 26860 KB Output is correct
100 Correct 138 ms 26816 KB Output is correct
101 Correct 29 ms 17868 KB Output is correct
102 Correct 29 ms 17868 KB Output is correct
103 Correct 109 ms 31972 KB Output is correct
104 Correct 108 ms 32104 KB Output is correct
105 Correct 244 ms 36628 KB Output is correct
106 Correct 247 ms 36656 KB Output is correct
107 Correct 162 ms 33680 KB Output is correct
108 Correct 158 ms 33816 KB Output is correct
109 Correct 34 ms 19148 KB Output is correct
110 Correct 27 ms 19156 KB Output is correct
111 Correct 27 ms 19156 KB Output is correct
112 Correct 32 ms 19152 KB Output is correct
113 Correct 127 ms 27608 KB Output is correct
114 Correct 110 ms 27552 KB Output is correct
115 Correct 270 ms 31936 KB Output is correct
116 Correct 254 ms 32112 KB Output is correct
117 Correct 154 ms 29232 KB Output is correct
118 Correct 165 ms 28872 KB Output is correct
119 Correct 28 ms 18136 KB Output is correct
120 Correct 28 ms 18128 KB Output is correct
121 Correct 131 ms 26716 KB Output is correct
122 Correct 124 ms 26820 KB Output is correct
123 Correct 266 ms 31692 KB Output is correct
124 Correct 252 ms 31276 KB Output is correct
125 Correct 160 ms 28356 KB Output is correct
126 Correct 178 ms 28412 KB Output is correct
127 Correct 31 ms 17880 KB Output is correct
128 Correct 31 ms 18128 KB Output is correct