답안 #908028

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
908028 2024-01-16T07:14:15 Z Trisanu_Das 새 집 (APIO18_new_home) C++17
80 / 100
5000 ms 33020 KB
#include <bits/stdc++.h>
 
const int INF = 0x3f3f3f3f;
 
struct store {
	int x, t, l, r;
	bool operator<(store arg) {
		return x < arg.x;
	}
};
 
struct query {
	int l, y, ind;
	bool operator<(query arg) {
		return y < arg.y;
	}
};
 
bool cmp_l(query a, query b) 
{
	return a.l < b.l;
}
 
const int N = 300000;
const int K = 600;
int n, k, q, next[N + 1], type_amt[N], ans[N], it[N], fi[N], last[N], right[N], to[N];
bool ut[N], active[N];
store a[N + 1];
query qr[N];
 
int main() 
{
	scanf("%d%d%d", &n, &k, &q);
	a[n].x = INF;
	next[n] = n;
	memset(to, 0x3f, k << 2);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d%d%d", &a[i].x, &a[i].t, &a[i].l, &a[i].r);
		--a[i].t;
		++a[i].r;
	}
	std::sort(a, a + n);
	for (int i = 0; i < q; ++i) {
		scanf("%d%d", &qr[i].l, &qr[i].y);
		qr[i].ind = i;
	}
	std::sort(qr, qr + q);
	for (int i = 0; i < q;) {
		memset(ut, 0, k);
		int until = std::min(i + K, q);
		std::vector<int> inter, inter_type;
		for (int j = 0; j < n; ++j) if (a[j].l >= qr[i].y + 1 && a[j].l <= qr[until - 1].y || a[j].r >= qr[i].y + 1 && a[j].r <= qr[until - 1].y) {
			if (!ut[a[j].t]) {
				inter_type.push_back(a[j].t);
				fi[a[j].t] = n;
			}
			ut[a[j].t] = 1;
			inter.push_back(j);
		}
		memset(last, -1, n << 2);
		for (int j = 0; j < n; ++j) {
			if (a[j].l <= qr[i].y && a[j].r > qr[until - 1].y) {
				if (ut[a[j].t]) {
					active[j] = false;
					if (last[a[j].t] == -1) fi[a[j].t] = j;
					else next[last[a[j].t]] = j;
					last[a[j].t] = j;
					next[j] = n;
				}
				else active[j] = true;
			}
			else active[j] = false;
		}
		for (int j = 0, l = 0, amt = 0; j < n; ++j) {
			while (l == j || l <= n && amt < k - inter_type.size()) {
				if (l < n && active[l]) {
					if (!type_amt[a[l].t]) ++amt;
					++type_amt[a[l].t];
				}
				++l;
			}
			right[j] = l;
			if (active[j]) {
				--type_amt[a[j].t];
				if (!type_amt[a[j].t]) --amt;
			}
		}
		std::sort(qr + i, qr + until, cmp_l);
		for (int j = 0; i < until; ++i) {
			while (qr[i].l - a[j].x > a[right[j] - 1].x - qr[i].l) ++j;
			int res = std::min(j ? qr[i].l - a[j - 1].x : INF, a[right[j] - 1].x - qr[i].l);
			for (int k = 0; k < (int)inter.size(); ++k) if (a[inter[k]].l <= qr[i].y && a[inter[k]].r > qr[i].y) to[a[inter[k]].t] = std::min(to[a[inter[k]].t], abs(qr[i].l - a[inter[k]].x));
			for (int k = 0; k < (int)inter_type.size(); ++k) {
				int cur = inter_type[k], &pos = fi[cur];
				while (a[next[pos]].x <= qr[i].l) pos = next[pos];
				res = std::max(res, std::min(to[cur], std::min(abs(qr[i].l - a[pos].x), a[next[pos]].x - qr[i].l)));
				to[cur] = INF;
			}
			ans[qr[i].ind] = res > INF / 2 ? -1 : res;
		}
	}
	for (int i = 0; i < q; ++i) printf("%d\n", ans[i]);
	return 0;
}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:52:57: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   52 |   for (int j = 0; j < n; ++j) if (a[j].l >= qr[i].y + 1 && a[j].l <= qr[until - 1].y || a[j].r >= qr[i].y + 1 && a[j].r <= qr[until - 1].y) {
      |                                   ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:75:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |    while (l == j || l <= n && amt < k - inter_type.size()) {
      |                               ~~~~^~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:75:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   75 |    while (l == j || l <= n && amt < k - inter_type.size()) {
      |                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |  scanf("%d%d%d", &n, &k, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%d%d%d%d", &a[i].x, &a[i].t, &a[i].l, &a[i].r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |   scanf("%d%d", &qr[i].l, &qr[i].y);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 3 ms 10588 KB Output is correct
6 Correct 3 ms 10588 KB Output is correct
7 Correct 4 ms 10588 KB Output is correct
8 Correct 3 ms 10712 KB Output is correct
9 Correct 4 ms 10840 KB Output is correct
10 Correct 3 ms 10588 KB Output is correct
11 Correct 3 ms 10584 KB Output is correct
12 Correct 3 ms 10696 KB Output is correct
13 Correct 3 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 3 ms 10588 KB Output is correct
16 Correct 3 ms 10588 KB Output is correct
17 Correct 4 ms 10720 KB Output is correct
18 Correct 3 ms 10588 KB Output is correct
19 Correct 3 ms 10732 KB Output is correct
20 Correct 3 ms 10592 KB Output is correct
21 Correct 3 ms 8540 KB Output is correct
22 Correct 4 ms 10716 KB Output is correct
23 Correct 3 ms 10600 KB Output is correct
24 Correct 3 ms 10728 KB Output is correct
25 Correct 3 ms 10592 KB Output is correct
26 Correct 3 ms 10596 KB Output is correct
27 Correct 3 ms 10592 KB Output is correct
28 Correct 3 ms 10708 KB Output is correct
29 Correct 3 ms 10592 KB Output is correct
30 Correct 3 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 3 ms 10588 KB Output is correct
6 Correct 3 ms 10588 KB Output is correct
7 Correct 4 ms 10588 KB Output is correct
8 Correct 3 ms 10712 KB Output is correct
9 Correct 4 ms 10840 KB Output is correct
10 Correct 3 ms 10588 KB Output is correct
11 Correct 3 ms 10584 KB Output is correct
12 Correct 3 ms 10696 KB Output is correct
13 Correct 3 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 3 ms 10588 KB Output is correct
16 Correct 3 ms 10588 KB Output is correct
17 Correct 4 ms 10720 KB Output is correct
18 Correct 3 ms 10588 KB Output is correct
19 Correct 3 ms 10732 KB Output is correct
20 Correct 3 ms 10592 KB Output is correct
21 Correct 3 ms 8540 KB Output is correct
22 Correct 4 ms 10716 KB Output is correct
23 Correct 3 ms 10600 KB Output is correct
24 Correct 3 ms 10728 KB Output is correct
25 Correct 3 ms 10592 KB Output is correct
26 Correct 3 ms 10596 KB Output is correct
27 Correct 3 ms 10592 KB Output is correct
28 Correct 3 ms 10708 KB Output is correct
29 Correct 3 ms 10592 KB Output is correct
30 Correct 3 ms 10588 KB Output is correct
31 Correct 528 ms 18412 KB Output is correct
32 Correct 397 ms 14416 KB Output is correct
33 Correct 484 ms 18264 KB Output is correct
34 Correct 594 ms 18516 KB Output is correct
35 Correct 445 ms 18516 KB Output is correct
36 Correct 390 ms 18256 KB Output is correct
37 Correct 420 ms 18288 KB Output is correct
38 Correct 408 ms 18328 KB Output is correct
39 Correct 278 ms 18156 KB Output is correct
40 Correct 312 ms 18256 KB Output is correct
41 Correct 496 ms 18648 KB Output is correct
42 Correct 530 ms 18424 KB Output is correct
43 Correct 83 ms 15912 KB Output is correct
44 Correct 467 ms 18516 KB Output is correct
45 Correct 330 ms 18372 KB Output is correct
46 Correct 260 ms 18316 KB Output is correct
47 Correct 117 ms 17984 KB Output is correct
48 Correct 114 ms 17964 KB Output is correct
49 Correct 266 ms 18096 KB Output is correct
50 Correct 360 ms 18348 KB Output is correct
51 Correct 249 ms 18128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1434 ms 30496 KB Output is correct
2 Correct 1825 ms 27912 KB Output is correct
3 Correct 1618 ms 31672 KB Output is correct
4 Correct 1470 ms 30668 KB Output is correct
5 Correct 1830 ms 27604 KB Output is correct
6 Correct 2171 ms 27868 KB Output is correct
7 Correct 1741 ms 31672 KB Output is correct
8 Correct 1517 ms 30668 KB Output is correct
9 Correct 1446 ms 30316 KB Output is correct
10 Correct 1506 ms 29216 KB Output is correct
11 Correct 1588 ms 28388 KB Output is correct
12 Correct 1483 ms 29084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4944 ms 30604 KB Output is correct
2 Correct 3307 ms 20188 KB Output is correct
3 Correct 3131 ms 29872 KB Output is correct
4 Correct 4254 ms 31880 KB Output is correct
5 Correct 4512 ms 31616 KB Output is correct
6 Correct 4488 ms 31804 KB Output is correct
7 Correct 3106 ms 29340 KB Output is correct
8 Correct 3113 ms 29848 KB Output is correct
9 Correct 3884 ms 32988 KB Output is correct
10 Correct 4200 ms 33020 KB Output is correct
11 Correct 4416 ms 30884 KB Output is correct
12 Correct 3417 ms 29884 KB Output is correct
13 Correct 1804 ms 29588 KB Output is correct
14 Correct 1679 ms 29472 KB Output is correct
15 Correct 2013 ms 29192 KB Output is correct
16 Correct 2374 ms 29816 KB Output is correct
17 Correct 2084 ms 29908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 3 ms 10588 KB Output is correct
6 Correct 3 ms 10588 KB Output is correct
7 Correct 4 ms 10588 KB Output is correct
8 Correct 3 ms 10712 KB Output is correct
9 Correct 4 ms 10840 KB Output is correct
10 Correct 3 ms 10588 KB Output is correct
11 Correct 3 ms 10584 KB Output is correct
12 Correct 3 ms 10696 KB Output is correct
13 Correct 3 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 3 ms 10588 KB Output is correct
16 Correct 3 ms 10588 KB Output is correct
17 Correct 4 ms 10720 KB Output is correct
18 Correct 3 ms 10588 KB Output is correct
19 Correct 3 ms 10732 KB Output is correct
20 Correct 3 ms 10592 KB Output is correct
21 Correct 3 ms 8540 KB Output is correct
22 Correct 4 ms 10716 KB Output is correct
23 Correct 3 ms 10600 KB Output is correct
24 Correct 3 ms 10728 KB Output is correct
25 Correct 3 ms 10592 KB Output is correct
26 Correct 3 ms 10596 KB Output is correct
27 Correct 3 ms 10592 KB Output is correct
28 Correct 3 ms 10708 KB Output is correct
29 Correct 3 ms 10592 KB Output is correct
30 Correct 3 ms 10588 KB Output is correct
31 Correct 528 ms 18412 KB Output is correct
32 Correct 397 ms 14416 KB Output is correct
33 Correct 484 ms 18264 KB Output is correct
34 Correct 594 ms 18516 KB Output is correct
35 Correct 445 ms 18516 KB Output is correct
36 Correct 390 ms 18256 KB Output is correct
37 Correct 420 ms 18288 KB Output is correct
38 Correct 408 ms 18328 KB Output is correct
39 Correct 278 ms 18156 KB Output is correct
40 Correct 312 ms 18256 KB Output is correct
41 Correct 496 ms 18648 KB Output is correct
42 Correct 530 ms 18424 KB Output is correct
43 Correct 83 ms 15912 KB Output is correct
44 Correct 467 ms 18516 KB Output is correct
45 Correct 330 ms 18372 KB Output is correct
46 Correct 260 ms 18316 KB Output is correct
47 Correct 117 ms 17984 KB Output is correct
48 Correct 114 ms 17964 KB Output is correct
49 Correct 266 ms 18096 KB Output is correct
50 Correct 360 ms 18348 KB Output is correct
51 Correct 249 ms 18128 KB Output is correct
52 Correct 716 ms 18528 KB Output is correct
53 Correct 1010 ms 20096 KB Output is correct
54 Correct 859 ms 18256 KB Output is correct
55 Correct 542 ms 16968 KB Output is correct
56 Correct 569 ms 16936 KB Output is correct
57 Correct 542 ms 17012 KB Output is correct
58 Correct 622 ms 18532 KB Output is correct
59 Correct 626 ms 16860 KB Output is correct
60 Correct 544 ms 18484 KB Output is correct
61 Correct 79 ms 16212 KB Output is correct
62 Correct 765 ms 18780 KB Output is correct
63 Correct 769 ms 16844 KB Output is correct
64 Correct 970 ms 18520 KB Output is correct
65 Correct 786 ms 18480 KB Output is correct
66 Correct 598 ms 16872 KB Output is correct
67 Correct 657 ms 14668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 3 ms 10588 KB Output is correct
6 Correct 3 ms 10588 KB Output is correct
7 Correct 4 ms 10588 KB Output is correct
8 Correct 3 ms 10712 KB Output is correct
9 Correct 4 ms 10840 KB Output is correct
10 Correct 3 ms 10588 KB Output is correct
11 Correct 3 ms 10584 KB Output is correct
12 Correct 3 ms 10696 KB Output is correct
13 Correct 3 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 3 ms 10588 KB Output is correct
16 Correct 3 ms 10588 KB Output is correct
17 Correct 4 ms 10720 KB Output is correct
18 Correct 3 ms 10588 KB Output is correct
19 Correct 3 ms 10732 KB Output is correct
20 Correct 3 ms 10592 KB Output is correct
21 Correct 3 ms 8540 KB Output is correct
22 Correct 4 ms 10716 KB Output is correct
23 Correct 3 ms 10600 KB Output is correct
24 Correct 3 ms 10728 KB Output is correct
25 Correct 3 ms 10592 KB Output is correct
26 Correct 3 ms 10596 KB Output is correct
27 Correct 3 ms 10592 KB Output is correct
28 Correct 3 ms 10708 KB Output is correct
29 Correct 3 ms 10592 KB Output is correct
30 Correct 3 ms 10588 KB Output is correct
31 Correct 528 ms 18412 KB Output is correct
32 Correct 397 ms 14416 KB Output is correct
33 Correct 484 ms 18264 KB Output is correct
34 Correct 594 ms 18516 KB Output is correct
35 Correct 445 ms 18516 KB Output is correct
36 Correct 390 ms 18256 KB Output is correct
37 Correct 420 ms 18288 KB Output is correct
38 Correct 408 ms 18328 KB Output is correct
39 Correct 278 ms 18156 KB Output is correct
40 Correct 312 ms 18256 KB Output is correct
41 Correct 496 ms 18648 KB Output is correct
42 Correct 530 ms 18424 KB Output is correct
43 Correct 83 ms 15912 KB Output is correct
44 Correct 467 ms 18516 KB Output is correct
45 Correct 330 ms 18372 KB Output is correct
46 Correct 260 ms 18316 KB Output is correct
47 Correct 117 ms 17984 KB Output is correct
48 Correct 114 ms 17964 KB Output is correct
49 Correct 266 ms 18096 KB Output is correct
50 Correct 360 ms 18348 KB Output is correct
51 Correct 249 ms 18128 KB Output is correct
52 Correct 1434 ms 30496 KB Output is correct
53 Correct 1825 ms 27912 KB Output is correct
54 Correct 1618 ms 31672 KB Output is correct
55 Correct 1470 ms 30668 KB Output is correct
56 Correct 1830 ms 27604 KB Output is correct
57 Correct 2171 ms 27868 KB Output is correct
58 Correct 1741 ms 31672 KB Output is correct
59 Correct 1517 ms 30668 KB Output is correct
60 Correct 1446 ms 30316 KB Output is correct
61 Correct 1506 ms 29216 KB Output is correct
62 Correct 1588 ms 28388 KB Output is correct
63 Correct 1483 ms 29084 KB Output is correct
64 Correct 4944 ms 30604 KB Output is correct
65 Correct 3307 ms 20188 KB Output is correct
66 Correct 3131 ms 29872 KB Output is correct
67 Correct 4254 ms 31880 KB Output is correct
68 Correct 4512 ms 31616 KB Output is correct
69 Correct 4488 ms 31804 KB Output is correct
70 Correct 3106 ms 29340 KB Output is correct
71 Correct 3113 ms 29848 KB Output is correct
72 Correct 3884 ms 32988 KB Output is correct
73 Correct 4200 ms 33020 KB Output is correct
74 Correct 4416 ms 30884 KB Output is correct
75 Correct 3417 ms 29884 KB Output is correct
76 Correct 1804 ms 29588 KB Output is correct
77 Correct 1679 ms 29472 KB Output is correct
78 Correct 2013 ms 29192 KB Output is correct
79 Correct 2374 ms 29816 KB Output is correct
80 Correct 2084 ms 29908 KB Output is correct
81 Correct 716 ms 18528 KB Output is correct
82 Correct 1010 ms 20096 KB Output is correct
83 Correct 859 ms 18256 KB Output is correct
84 Correct 542 ms 16968 KB Output is correct
85 Correct 569 ms 16936 KB Output is correct
86 Correct 542 ms 17012 KB Output is correct
87 Correct 622 ms 18532 KB Output is correct
88 Correct 626 ms 16860 KB Output is correct
89 Correct 544 ms 18484 KB Output is correct
90 Correct 79 ms 16212 KB Output is correct
91 Correct 765 ms 18780 KB Output is correct
92 Correct 769 ms 16844 KB Output is correct
93 Correct 970 ms 18520 KB Output is correct
94 Correct 786 ms 18480 KB Output is correct
95 Correct 598 ms 16872 KB Output is correct
96 Correct 657 ms 14668 KB Output is correct
97 Execution timed out 5051 ms 32800 KB Time limit exceeded
98 Halted 0 ms 0 KB -