Submission #727638

# Submission time Handle Problem Language Result Execution time Memory
727638 2023-04-21T04:22:00 Z SanguineChameleon New Home (APIO18_new_home) C++17
5 / 100
5000 ms 38044 KB
#include <bits/stdc++.h>
using namespace std;

void just_do_it();

int main() {
	#ifdef KAMIRULEZ
		freopen("kamirulez.inp", "r", stdin);
		freopen("kamirulez.out", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	just_do_it();
	return 0;
}

struct store {
	int pos, type, left_T, right_T;
};

struct query {
	int pos, T;
};

const int inf = 1e8 + 20;
const int maxn = 3e5 + 20;
store S[maxn];
query Q[maxn];
int res[maxn];
int A[maxn];
int n, k, q;

void add(int pos, int val) {
	A[pos] = val;
}

void rem(int pos, int val) {
	A[pos] = 0;
}

bool check(int lt, int rt) {
	set<int> types;
	for (int i = lt; i <= rt; i++) {
		if (A[i]) {
			types.insert(A[i]);
		}
	}
	return (int)types.size() == k;
}

void just_do_it() {
	cin >> n >> k >> q;
	vector<pair<int, int>> sorted_pos;
	vector<pair<int, pair<int, int>>> events;
	for (int i = 1; i <= n; i++) {
		cin >> S[i].pos >> S[i].type >> S[i].left_T >> S[i].right_T;
		sorted_pos.push_back({S[i].pos, i});
		events.push_back({S[i].left_T, {1, i}});
		events.push_back({S[i].right_T, {3, i}});
	}
	sort(sorted_pos.begin(), sorted_pos.end());
	for (int i = 1; i <= n; i++) {
		S[sorted_pos[i - 1].second].pos = i;
	}
	for (int i = 1; i <= q; i++) {
		cin >> Q[i].pos >> Q[i].T;
		events.push_back({Q[i].T, {2, i}});
	}
	sort(events.begin(), events.end());
	for (auto e: events) {
		int type = e.second.first;
		int id = e.second.second;
		if (type == 1) {
			add(S[id].pos, S[id].type);
		}
		if (type == 2) {
			res[id] = -1;
			int lt = 0;
			int rt = inf;
			while (lt <= rt) {
				int mt = (lt + rt) / 2;
				int ql = lower_bound(sorted_pos.begin(), sorted_pos.end(), make_pair(Q[id].pos - mt, -inf)) - sorted_pos.begin() + 1;
				int qr = upper_bound(sorted_pos.begin(), sorted_pos.end(), make_pair(Q[id].pos + mt, inf)) - sorted_pos.begin();
				if (ql <= qr && check(ql, qr)) {
					res[id] = mt;
					rt = mt - 1;
				}
				else {
					lt = mt + 1;
				}
			}
		}
		if (type == 3) {
			rem(S[id].pos, S[id].type);
		}
	}
	for (int i = 1; i <= q; i++) {
		cout << res[i] << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 12 ms 420 KB Output is correct
6 Correct 9 ms 388 KB Output is correct
7 Correct 56 ms 340 KB Output is correct
8 Correct 71 ms 340 KB Output is correct
9 Correct 124 ms 416 KB Output is correct
10 Correct 14 ms 432 KB Output is correct
11 Correct 9 ms 340 KB Output is correct
12 Correct 4 ms 388 KB Output is correct
13 Correct 4 ms 340 KB Output is correct
14 Correct 3 ms 432 KB Output is correct
15 Correct 88 ms 408 KB Output is correct
16 Correct 130 ms 416 KB Output is correct
17 Correct 35 ms 340 KB Output is correct
18 Correct 78 ms 408 KB Output is correct
19 Correct 118 ms 412 KB Output is correct
20 Correct 36 ms 340 KB Output is correct
21 Correct 43 ms 404 KB Output is correct
22 Correct 179 ms 340 KB Output is correct
23 Correct 104 ms 340 KB Output is correct
24 Correct 73 ms 340 KB Output is correct
25 Correct 27 ms 340 KB Output is correct
26 Correct 4 ms 340 KB Output is correct
27 Correct 22 ms 400 KB Output is correct
28 Correct 6 ms 340 KB Output is correct
29 Correct 4 ms 340 KB Output is correct
30 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 12 ms 420 KB Output is correct
6 Correct 9 ms 388 KB Output is correct
7 Correct 56 ms 340 KB Output is correct
8 Correct 71 ms 340 KB Output is correct
9 Correct 124 ms 416 KB Output is correct
10 Correct 14 ms 432 KB Output is correct
11 Correct 9 ms 340 KB Output is correct
12 Correct 4 ms 388 KB Output is correct
13 Correct 4 ms 340 KB Output is correct
14 Correct 3 ms 432 KB Output is correct
15 Correct 88 ms 408 KB Output is correct
16 Correct 130 ms 416 KB Output is correct
17 Correct 35 ms 340 KB Output is correct
18 Correct 78 ms 408 KB Output is correct
19 Correct 118 ms 412 KB Output is correct
20 Correct 36 ms 340 KB Output is correct
21 Correct 43 ms 404 KB Output is correct
22 Correct 179 ms 340 KB Output is correct
23 Correct 104 ms 340 KB Output is correct
24 Correct 73 ms 340 KB Output is correct
25 Correct 27 ms 340 KB Output is correct
26 Correct 4 ms 340 KB Output is correct
27 Correct 22 ms 400 KB Output is correct
28 Correct 6 ms 340 KB Output is correct
29 Correct 4 ms 340 KB Output is correct
30 Correct 3 ms 340 KB Output is correct
31 Execution timed out 5044 ms 7948 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5020 ms 38044 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5047 ms 35184 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 12 ms 420 KB Output is correct
6 Correct 9 ms 388 KB Output is correct
7 Correct 56 ms 340 KB Output is correct
8 Correct 71 ms 340 KB Output is correct
9 Correct 124 ms 416 KB Output is correct
10 Correct 14 ms 432 KB Output is correct
11 Correct 9 ms 340 KB Output is correct
12 Correct 4 ms 388 KB Output is correct
13 Correct 4 ms 340 KB Output is correct
14 Correct 3 ms 432 KB Output is correct
15 Correct 88 ms 408 KB Output is correct
16 Correct 130 ms 416 KB Output is correct
17 Correct 35 ms 340 KB Output is correct
18 Correct 78 ms 408 KB Output is correct
19 Correct 118 ms 412 KB Output is correct
20 Correct 36 ms 340 KB Output is correct
21 Correct 43 ms 404 KB Output is correct
22 Correct 179 ms 340 KB Output is correct
23 Correct 104 ms 340 KB Output is correct
24 Correct 73 ms 340 KB Output is correct
25 Correct 27 ms 340 KB Output is correct
26 Correct 4 ms 340 KB Output is correct
27 Correct 22 ms 400 KB Output is correct
28 Correct 6 ms 340 KB Output is correct
29 Correct 4 ms 340 KB Output is correct
30 Correct 3 ms 340 KB Output is correct
31 Execution timed out 5044 ms 7948 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 12 ms 420 KB Output is correct
6 Correct 9 ms 388 KB Output is correct
7 Correct 56 ms 340 KB Output is correct
8 Correct 71 ms 340 KB Output is correct
9 Correct 124 ms 416 KB Output is correct
10 Correct 14 ms 432 KB Output is correct
11 Correct 9 ms 340 KB Output is correct
12 Correct 4 ms 388 KB Output is correct
13 Correct 4 ms 340 KB Output is correct
14 Correct 3 ms 432 KB Output is correct
15 Correct 88 ms 408 KB Output is correct
16 Correct 130 ms 416 KB Output is correct
17 Correct 35 ms 340 KB Output is correct
18 Correct 78 ms 408 KB Output is correct
19 Correct 118 ms 412 KB Output is correct
20 Correct 36 ms 340 KB Output is correct
21 Correct 43 ms 404 KB Output is correct
22 Correct 179 ms 340 KB Output is correct
23 Correct 104 ms 340 KB Output is correct
24 Correct 73 ms 340 KB Output is correct
25 Correct 27 ms 340 KB Output is correct
26 Correct 4 ms 340 KB Output is correct
27 Correct 22 ms 400 KB Output is correct
28 Correct 6 ms 340 KB Output is correct
29 Correct 4 ms 340 KB Output is correct
30 Correct 3 ms 340 KB Output is correct
31 Execution timed out 5044 ms 7948 KB Time limit exceeded
32 Halted 0 ms 0 KB -