Submission #919445

# Submission time Handle Problem Language Result Execution time Memory
919445 2024-01-31T20:05:59 Z NK_ Vinjete (COI22_vinjete) C++17
100 / 100
426 ms 232016 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define f first
#define s second
#define mp make_pair
#define nl '\n'
#define pb push_back

template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;

const int INF = 1 << 30;

struct node {
	node* c[2]; int L, R, ans, T;

	node(int l, int r): L(l), R(r) { ans = 0, T = INF; c[0] = c[1] = NULL; };

	void pull() {
		if (T != INF) ans = R - L + 1;
		else ans = (c[0] ? c[0]->ans : 0) + (c[1] ? c[1]->ans : 0);
	}

	void upd(int l, int r, int t) {
		// cout << L << " " << R << " " << T << " " << ans << endl;
		if (r < L || R < l || T < t) return;
		if (l <= L && R <= r) {
			if (t > 0) T = t;
			else {
				if (T == -t) T = INF;
				else return;
			}
			pull();
			// cout << "UPD: " << L << " " << R << " " << T << " " << ans << endl;
			return;
		}


		int M = (L + R) / 2;

		if (!c[0]) c[0] = new node(L, M);
		if (!c[1]) c[1] = new node(M + 1, R);

		c[0]->upd(l, r, t);
		c[1]->upd(l, r, t);

		pull();
	}
};

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	node* st = new node(0, INF - 1);

	int N, M; cin >> N >> M;

	V<vpi> adj(N); vi L(N - 1), R(N - 1);

	for(int i = 0; i < N - 1; i++) {
		int u, v, l, r; cin >> u >> v >> l >> r; --u, --v, --l, --r;
		adj[u].pb(mp(v, i));
		adj[v].pb(mp(u, i));
		L[i] = l, R[i] = r;
	}

	int t = 1;
	vi ans(N);
	function<void(int, int)> dfs = [&](int u, int p) {
		ans[u] = st->ans;

		t++;
		for(auto& e : adj[u]) if (e.f != p) {
			int v, i; tie(v, i) = e;

			int cur = t;
			st->upd(L[i], R[i], cur);
			dfs(v, u);
			st->upd(L[i], R[i], -cur);
		}
	};

	dfs(0, -1);

	for(int i = 1; i < N; i++) cout << ans[i] << nl;

	exit(0-0);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 2 ms 600 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 2 ms 344 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 2 ms 600 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 2 ms 344 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 2 ms 600 KB Output is correct
26 Correct 2 ms 600 KB Output is correct
27 Correct 4 ms 3928 KB Output is correct
28 Correct 4 ms 3932 KB Output is correct
29 Correct 3 ms 2392 KB Output is correct
30 Correct 3 ms 2396 KB Output is correct
31 Correct 5 ms 3932 KB Output is correct
32 Correct 4 ms 3932 KB Output is correct
33 Correct 7 ms 3928 KB Output is correct
34 Correct 5 ms 3928 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 4 ms 3932 KB Output is correct
38 Correct 5 ms 3860 KB Output is correct
39 Correct 3 ms 2396 KB Output is correct
40 Correct 3 ms 2392 KB Output is correct
41 Correct 4 ms 3928 KB Output is correct
42 Correct 4 ms 3932 KB Output is correct
43 Correct 2 ms 348 KB Output is correct
44 Correct 2 ms 348 KB Output is correct
45 Correct 4 ms 3928 KB Output is correct
46 Correct 4 ms 3672 KB Output is correct
47 Correct 3 ms 2236 KB Output is correct
48 Correct 4 ms 2392 KB Output is correct
49 Correct 5 ms 3932 KB Output is correct
50 Correct 5 ms 3928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 2 ms 600 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 2 ms 344 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 35 ms 7760 KB Output is correct
26 Correct 36 ms 7768 KB Output is correct
27 Correct 47 ms 11544 KB Output is correct
28 Correct 46 ms 11344 KB Output is correct
29 Correct 46 ms 11268 KB Output is correct
30 Correct 44 ms 11344 KB Output is correct
31 Correct 6 ms 3160 KB Output is correct
32 Correct 7 ms 3164 KB Output is correct
33 Correct 7 ms 3160 KB Output is correct
34 Correct 6 ms 3160 KB Output is correct
35 Correct 38 ms 4688 KB Output is correct
36 Correct 35 ms 4692 KB Output is correct
37 Correct 48 ms 8020 KB Output is correct
38 Correct 47 ms 8212 KB Output is correct
39 Correct 45 ms 8260 KB Output is correct
40 Correct 44 ms 8024 KB Output is correct
41 Correct 7 ms 2652 KB Output is correct
42 Correct 9 ms 3028 KB Output is correct
43 Correct 39 ms 4184 KB Output is correct
44 Correct 42 ms 4432 KB Output is correct
45 Correct 48 ms 7760 KB Output is correct
46 Correct 53 ms 7748 KB Output is correct
47 Correct 45 ms 7760 KB Output is correct
48 Correct 53 ms 7760 KB Output is correct
49 Correct 8 ms 2652 KB Output is correct
50 Correct 7 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 2 ms 600 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 2 ms 344 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 35 ms 7760 KB Output is correct
26 Correct 36 ms 7768 KB Output is correct
27 Correct 47 ms 11544 KB Output is correct
28 Correct 46 ms 11344 KB Output is correct
29 Correct 46 ms 11268 KB Output is correct
30 Correct 44 ms 11344 KB Output is correct
31 Correct 6 ms 3160 KB Output is correct
32 Correct 7 ms 3164 KB Output is correct
33 Correct 7 ms 3160 KB Output is correct
34 Correct 6 ms 3160 KB Output is correct
35 Correct 38 ms 4688 KB Output is correct
36 Correct 35 ms 4692 KB Output is correct
37 Correct 48 ms 8020 KB Output is correct
38 Correct 47 ms 8212 KB Output is correct
39 Correct 45 ms 8260 KB Output is correct
40 Correct 44 ms 8024 KB Output is correct
41 Correct 7 ms 2652 KB Output is correct
42 Correct 9 ms 3028 KB Output is correct
43 Correct 39 ms 4184 KB Output is correct
44 Correct 42 ms 4432 KB Output is correct
45 Correct 48 ms 7760 KB Output is correct
46 Correct 53 ms 7748 KB Output is correct
47 Correct 45 ms 7760 KB Output is correct
48 Correct 53 ms 7760 KB Output is correct
49 Correct 8 ms 2652 KB Output is correct
50 Correct 7 ms 2648 KB Output is correct
51 Correct 89 ms 19024 KB Output is correct
52 Correct 91 ms 19024 KB Output is correct
53 Correct 118 ms 27984 KB Output is correct
54 Correct 124 ms 27976 KB Output is correct
55 Correct 116 ms 27984 KB Output is correct
56 Correct 120 ms 27988 KB Output is correct
57 Correct 23 ms 9808 KB Output is correct
58 Correct 24 ms 9748 KB Output is correct
59 Correct 24 ms 10076 KB Output is correct
60 Correct 23 ms 9552 KB Output is correct
61 Correct 93 ms 11324 KB Output is correct
62 Correct 91 ms 11572 KB Output is correct
63 Correct 130 ms 19868 KB Output is correct
64 Correct 129 ms 19900 KB Output is correct
65 Correct 118 ms 20308 KB Output is correct
66 Correct 120 ms 19916 KB Output is correct
67 Correct 23 ms 8020 KB Output is correct
68 Correct 24 ms 8024 KB Output is correct
69 Correct 108 ms 10324 KB Output is correct
70 Correct 105 ms 10320 KB Output is correct
71 Correct 148 ms 19024 KB Output is correct
72 Correct 149 ms 18920 KB Output is correct
73 Correct 126 ms 19024 KB Output is correct
74 Correct 128 ms 19040 KB Output is correct
75 Correct 27 ms 7760 KB Output is correct
76 Correct 26 ms 8024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 2 ms 600 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 2 ms 344 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 2 ms 600 KB Output is correct
26 Correct 2 ms 600 KB Output is correct
27 Correct 4 ms 3928 KB Output is correct
28 Correct 4 ms 3932 KB Output is correct
29 Correct 3 ms 2392 KB Output is correct
30 Correct 3 ms 2396 KB Output is correct
31 Correct 5 ms 3932 KB Output is correct
32 Correct 4 ms 3932 KB Output is correct
33 Correct 7 ms 3928 KB Output is correct
34 Correct 5 ms 3928 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 4 ms 3932 KB Output is correct
38 Correct 5 ms 3860 KB Output is correct
39 Correct 3 ms 2396 KB Output is correct
40 Correct 3 ms 2392 KB Output is correct
41 Correct 4 ms 3928 KB Output is correct
42 Correct 4 ms 3932 KB Output is correct
43 Correct 2 ms 348 KB Output is correct
44 Correct 2 ms 348 KB Output is correct
45 Correct 4 ms 3928 KB Output is correct
46 Correct 4 ms 3672 KB Output is correct
47 Correct 3 ms 2236 KB Output is correct
48 Correct 4 ms 2392 KB Output is correct
49 Correct 5 ms 3932 KB Output is correct
50 Correct 5 ms 3928 KB Output is correct
51 Correct 35 ms 7760 KB Output is correct
52 Correct 36 ms 7768 KB Output is correct
53 Correct 47 ms 11544 KB Output is correct
54 Correct 46 ms 11344 KB Output is correct
55 Correct 46 ms 11268 KB Output is correct
56 Correct 44 ms 11344 KB Output is correct
57 Correct 6 ms 3160 KB Output is correct
58 Correct 7 ms 3164 KB Output is correct
59 Correct 7 ms 3160 KB Output is correct
60 Correct 6 ms 3160 KB Output is correct
61 Correct 38 ms 4688 KB Output is correct
62 Correct 35 ms 4692 KB Output is correct
63 Correct 48 ms 8020 KB Output is correct
64 Correct 47 ms 8212 KB Output is correct
65 Correct 45 ms 8260 KB Output is correct
66 Correct 44 ms 8024 KB Output is correct
67 Correct 7 ms 2652 KB Output is correct
68 Correct 9 ms 3028 KB Output is correct
69 Correct 39 ms 4184 KB Output is correct
70 Correct 42 ms 4432 KB Output is correct
71 Correct 48 ms 7760 KB Output is correct
72 Correct 53 ms 7748 KB Output is correct
73 Correct 45 ms 7760 KB Output is correct
74 Correct 53 ms 7760 KB Output is correct
75 Correct 8 ms 2652 KB Output is correct
76 Correct 7 ms 2648 KB Output is correct
77 Correct 89 ms 19024 KB Output is correct
78 Correct 91 ms 19024 KB Output is correct
79 Correct 118 ms 27984 KB Output is correct
80 Correct 124 ms 27976 KB Output is correct
81 Correct 116 ms 27984 KB Output is correct
82 Correct 120 ms 27988 KB Output is correct
83 Correct 23 ms 9808 KB Output is correct
84 Correct 24 ms 9748 KB Output is correct
85 Correct 24 ms 10076 KB Output is correct
86 Correct 23 ms 9552 KB Output is correct
87 Correct 93 ms 11324 KB Output is correct
88 Correct 91 ms 11572 KB Output is correct
89 Correct 130 ms 19868 KB Output is correct
90 Correct 129 ms 19900 KB Output is correct
91 Correct 118 ms 20308 KB Output is correct
92 Correct 120 ms 19916 KB Output is correct
93 Correct 23 ms 8020 KB Output is correct
94 Correct 24 ms 8024 KB Output is correct
95 Correct 108 ms 10324 KB Output is correct
96 Correct 105 ms 10320 KB Output is correct
97 Correct 148 ms 19024 KB Output is correct
98 Correct 149 ms 18920 KB Output is correct
99 Correct 126 ms 19024 KB Output is correct
100 Correct 128 ms 19040 KB Output is correct
101 Correct 27 ms 7760 KB Output is correct
102 Correct 26 ms 8024 KB Output is correct
103 Correct 104 ms 20000 KB Output is correct
104 Correct 103 ms 19792 KB Output is correct
105 Correct 373 ms 232016 KB Output is correct
106 Correct 379 ms 231524 KB Output is correct
107 Correct 311 ms 146000 KB Output is correct
108 Correct 318 ms 146000 KB Output is correct
109 Correct 76 ms 55968 KB Output is correct
110 Correct 79 ms 55888 KB Output is correct
111 Correct 75 ms 55888 KB Output is correct
112 Correct 79 ms 55888 KB Output is correct
113 Correct 118 ms 12468 KB Output is correct
114 Correct 108 ms 12368 KB Output is correct
115 Correct 389 ms 224080 KB Output is correct
116 Correct 378 ms 224344 KB Output is correct
117 Correct 266 ms 138320 KB Output is correct
118 Correct 255 ms 137636 KB Output is correct
119 Correct 71 ms 54452 KB Output is correct
120 Correct 69 ms 54352 KB Output is correct
121 Correct 136 ms 11172 KB Output is correct
122 Correct 142 ms 11020 KB Output is correct
123 Correct 426 ms 223056 KB Output is correct
124 Correct 410 ms 223056 KB Output is correct
125 Correct 265 ms 136784 KB Output is correct
126 Correct 268 ms 136784 KB Output is correct
127 Correct 72 ms 54096 KB Output is correct
128 Correct 74 ms 54096 KB Output is correct