Submission #405103

# Submission time Handle Problem Language Result Execution time Memory
405103 2021-05-15T17:32:15 Z BERNARB01 New Home (APIO18_new_home) C++17
12 / 100
5000 ms 34216 KB
#include <bits/stdc++.h>

using namespace std;

class bag {
private:
	vector<multiset<int>> g;
public:
	bag(int k) {
		g.resize(k);
	}
	void add(int idx, int k) {
		g[k].insert(idx);
	}
	void rem(int idx, int k) {
		g[k].erase(g[k].find(idx));
	}
	//int qry(int lx, int rx) {
		
	//}
	int qry(int x) {
		for (int k = 0; k < (int) g.size(); k++) {
			if (g[k].empty()) {
				return -1;
			}
		}
		int ans = 0;
		for (int k = 0; k < (int) g.size(); k++) {
			auto lo = g[k].lower_bound(x);
			if (lo == g[k].end()) {
				ans = max(ans, abs(x - *prev(lo)));
			} else if (lo == g[k].begin()) {
				ans = max(ans, abs(x - *lo));
			} else {
				ans = max(ans, min(abs(x - *lo), abs(x - *prev(lo))));
			}
		}
		return ans;
	}
};

const int start = 0;
const int query = 1;
const int endd = 2;

class E {
public:
	int op, x, ty, ti;
	E(int opp, int xx, int tyy, int tii) {
		op = opp;
		x = xx;
		ty = tyy;
		ti = tii;
	}
	bool operator <(const E& o) {
		if (ti == o.ti) {
			return op < o.op;
		}
		return ti < o.ti;
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k, q;
	cin >> n >> k >> q;
	vector<E> events;
	for (int i = 0; i < n; i++) {
		int x, t, a, b;
		cin >> x >> t >> a >> b;
		--t;
		events.emplace_back(E(start, x, t, a));
		events.emplace_back(E(endd, x, t, b));
	}
	for (int i = 0; i < q; i++) {
		int l, y;
		cin >> l >> y;
		events.emplace_back(E(query, l, i, y));
	}
	sort(events.begin(), events.end());
	vector<int> ans(q);
	bag mrsrtr(k);
	for (int i = 0; i < (int) events.size(); i++) {
		if (events[i].op == start) {
			mrsrtr.add(events[i].x, events[i].ty);
		} else if (events[i].op == query) {
			//int l = -1, r = 1e8;
			//while (r - l > 1) {
				//int mid = (l + r) >> 1;
				//if (mrsrtr.qry(max(events[i].x - mid, 0), min(events[i].x + mid, (int) 1e8)) == k) {
					//r = mid;
				//} else {
					//l = mid;
				//}
				int r = mrsrtr.qry(events[i].x);
				ans[events[i].ty] = r;
			//}
		} else {
			mrsrtr.rem(events[i].x, events[i].ty);
		}
	}
	for (int x : ans) {
		cout << x << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 380 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 368 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 320 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 1 ms 312 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 380 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 368 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 320 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 1 ms 312 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2131 ms 9616 KB Output is correct
32 Correct 111 ms 5516 KB Output is correct
33 Correct 181 ms 7568 KB Output is correct
34 Correct 1611 ms 7868 KB Output is correct
35 Correct 928 ms 9552 KB Output is correct
36 Correct 209 ms 9380 KB Output is correct
37 Correct 169 ms 6864 KB Output is correct
38 Correct 105 ms 6716 KB Output is correct
39 Correct 90 ms 6608 KB Output is correct
40 Correct 91 ms 6700 KB Output is correct
41 Correct 289 ms 6840 KB Output is correct
42 Correct 239 ms 6732 KB Output is correct
43 Correct 328 ms 9040 KB Output is correct
44 Correct 282 ms 6832 KB Output is correct
45 Correct 127 ms 6832 KB Output is correct
46 Correct 76 ms 6716 KB Output is correct
47 Correct 79 ms 6692 KB Output is correct
48 Correct 69 ms 6712 KB Output is correct
49 Correct 85 ms 6716 KB Output is correct
50 Correct 152 ms 6624 KB Output is correct
51 Correct 81 ms 6604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5057 ms 34216 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5085 ms 31504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 380 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 368 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 320 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 1 ms 312 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2131 ms 9616 KB Output is correct
32 Correct 111 ms 5516 KB Output is correct
33 Correct 181 ms 7568 KB Output is correct
34 Correct 1611 ms 7868 KB Output is correct
35 Correct 928 ms 9552 KB Output is correct
36 Correct 209 ms 9380 KB Output is correct
37 Correct 169 ms 6864 KB Output is correct
38 Correct 105 ms 6716 KB Output is correct
39 Correct 90 ms 6608 KB Output is correct
40 Correct 91 ms 6700 KB Output is correct
41 Correct 289 ms 6840 KB Output is correct
42 Correct 239 ms 6732 KB Output is correct
43 Correct 328 ms 9040 KB Output is correct
44 Correct 282 ms 6832 KB Output is correct
45 Correct 127 ms 6832 KB Output is correct
46 Correct 76 ms 6716 KB Output is correct
47 Correct 79 ms 6692 KB Output is correct
48 Correct 69 ms 6712 KB Output is correct
49 Correct 85 ms 6716 KB Output is correct
50 Correct 152 ms 6624 KB Output is correct
51 Correct 81 ms 6604 KB Output is correct
52 Correct 82 ms 12200 KB Output is correct
53 Correct 80 ms 10384 KB Output is correct
54 Correct 96 ms 10312 KB Output is correct
55 Execution timed out 5070 ms 8300 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 380 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 368 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 320 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 1 ms 312 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2131 ms 9616 KB Output is correct
32 Correct 111 ms 5516 KB Output is correct
33 Correct 181 ms 7568 KB Output is correct
34 Correct 1611 ms 7868 KB Output is correct
35 Correct 928 ms 9552 KB Output is correct
36 Correct 209 ms 9380 KB Output is correct
37 Correct 169 ms 6864 KB Output is correct
38 Correct 105 ms 6716 KB Output is correct
39 Correct 90 ms 6608 KB Output is correct
40 Correct 91 ms 6700 KB Output is correct
41 Correct 289 ms 6840 KB Output is correct
42 Correct 239 ms 6732 KB Output is correct
43 Correct 328 ms 9040 KB Output is correct
44 Correct 282 ms 6832 KB Output is correct
45 Correct 127 ms 6832 KB Output is correct
46 Correct 76 ms 6716 KB Output is correct
47 Correct 79 ms 6692 KB Output is correct
48 Correct 69 ms 6712 KB Output is correct
49 Correct 85 ms 6716 KB Output is correct
50 Correct 152 ms 6624 KB Output is correct
51 Correct 81 ms 6604 KB Output is correct
52 Execution timed out 5057 ms 34216 KB Time limit exceeded
53 Halted 0 ms 0 KB -