답안 #381772

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
381772 2021-03-25T21:39:42 Z rainboy 원 고르기 (APIO18_circle_selection) C
100 / 100
1068 ms 13036 KB
/* https://oj.uz/submission/66132 (Benq) */
#include <stdio.h>
#include <string.h>

#define N	300000
#define X	1000000000

unsigned int Z = 12345;

int rand_() {
	return (Z *= 3) >> 1;
}

int xx[N], yy[N], rr[N];

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k) {
			int c = rr[ii[j]] != rr[i_] ? rr[i_] - rr[ii[j]] : ii[j] - i_;

			if (c == 0)
				j++;
			else if (c < 0) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		}
		sort(ii, l, i);
		l = k;
	}
}

int ii_[N], xx_[N], yy_[N], n, lg;

int idx(int x, int y) {
	int lower = -1, upper = n;

	while (upper - lower > 1) {
		int i = (lower + upper) / 2, x_ = xx_[ii_[i]], y_ = yy_[ii_[i]];

		if (x_ < x || x_ == x && y_ <= y)
			lower = i;
		else
			upper = i;
	}
	return lower;
}

int main() {
	static int ii[N], ii1[N], pp[N];
	int h, h_, i, j, cnt;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d%d%d", &xx[i], &yy[i], &rr[i]);
		xx[i] += X, yy[i] += X;
		ii[i] = ii_[i] = i;
	}
	sort(ii, 0, n);
	memset(pp, -1, n * sizeof *pp);
	for (lg = 30, h = 0; lg >= 0; lg--) {
		int x, y, dx;

		for (i = 0; i < n; i++)
			xx_[i] = xx[i] >> lg + 1, yy_[i] = yy[i] >> lg + 1;
		while (h < n && rr[ii[h]] >= 1 << lg) {
			i = ii[h], x = xx_[i], y = yy_[i];
			if (pp[i] == -1)
				for (dx = -2; dx <= 2; dx++) {
					h_ = idx(x + dx, y - 3) + 1;
					while (h_ < n && xx_[ii_[h_]] == x + dx && yy_[ii_[h_]] <= y + 2) {
						j = ii_[h_];
						if (pp[j] == -1 && (long long) (xx[i] - xx[j]) * (xx[i] - xx[j]) + (long long) (yy[i] - yy[j]) * (yy[i] - yy[j]) <= (long long) (rr[i] + rr[j]) * (rr[i] + rr[j]))
							pp[j] = i;
						h_++;
					}
				}
			h++;
		}
		for (i = 0; i < n; i = j) {
			x = xx_[ii_[i]];
			j = i + 1;
			while (j < n && xx_[ii_[j]] == x)
				j++;
			cnt = 0;
			for (h_ = i; h_ < j; h_++)
				if ((xx[ii_[h_]] >> lg & 1) == 0)
					ii_[i++] = ii_[h_];
				else
					ii1[cnt++] = ii_[h_];
			memcpy(ii_ + i, ii1, cnt * sizeof *ii1);
		}
		for (i = 0; i < n; i = j) {
			x = xx[ii_[i]] >> lg, y = yy_[ii_[i]];
			j = i + 1;
			while (j < n && (xx[ii_[j]] >> lg) == x && yy_[ii_[j]] == y)
				j++;
			cnt = 0;
			for (h_ = i; h_ < j; h_++)
				if ((yy[ii_[h_]] >> lg & 1) == 0)
					ii_[i++] = ii_[h_];
				else
					ii1[cnt++] = ii_[h_];
			memcpy(ii_ + i, ii1, cnt * sizeof *ii1);
		}
	}
	for (i = 0; i < n; i++)
		printf("%d ", pp[i] + 1);
	printf("\n");
	return 0;
}

Compilation message

circle_selection.c: In function 'idx':
circle_selection.c:46:25: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   46 |   if (x_ < x || x_ == x && y_ <= y)
      |                 ~~~~~~~~^~~~~~~~~~
circle_selection.c: In function 'main':
circle_selection.c:70:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   70 |    xx_[i] = xx[i] >> lg + 1, yy_[i] = yy[i] >> lg + 1;
      |                      ~~~^~~
circle_selection.c:70:51: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   70 |    xx_[i] = xx[i] >> lg + 1, yy_[i] = yy[i] >> lg + 1;
      |                                                ~~~^~~
circle_selection.c:58:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   58 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
circle_selection.c:60:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   60 |   scanf("%d%d%d", &xx[i], &yy[i], &rr[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 8 ms 492 KB Output is correct
20 Correct 9 ms 492 KB Output is correct
21 Correct 9 ms 492 KB Output is correct
22 Correct 11 ms 492 KB Output is correct
23 Correct 12 ms 636 KB Output is correct
24 Correct 11 ms 492 KB Output is correct
25 Correct 11 ms 492 KB Output is correct
26 Correct 11 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 455 ms 12636 KB Output is correct
2 Correct 460 ms 12396 KB Output is correct
3 Correct 461 ms 12652 KB Output is correct
4 Correct 466 ms 12644 KB Output is correct
5 Correct 354 ms 12780 KB Output is correct
6 Correct 538 ms 13036 KB Output is correct
7 Correct 426 ms 12908 KB Output is correct
8 Correct 430 ms 12908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 287 ms 4332 KB Output is correct
3 Correct 1068 ms 12396 KB Output is correct
4 Correct 977 ms 12268 KB Output is correct
5 Correct 946 ms 12012 KB Output is correct
6 Correct 375 ms 6508 KB Output is correct
7 Correct 184 ms 3544 KB Output is correct
8 Correct 32 ms 1004 KB Output is correct
9 Correct 966 ms 12268 KB Output is correct
10 Correct 838 ms 12200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 888 ms 12516 KB Output is correct
2 Correct 862 ms 12840 KB Output is correct
3 Correct 609 ms 12012 KB Output is correct
4 Correct 808 ms 12524 KB Output is correct
5 Correct 902 ms 12672 KB Output is correct
6 Correct 569 ms 12268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 8 ms 492 KB Output is correct
20 Correct 9 ms 492 KB Output is correct
21 Correct 9 ms 492 KB Output is correct
22 Correct 11 ms 492 KB Output is correct
23 Correct 12 ms 636 KB Output is correct
24 Correct 11 ms 492 KB Output is correct
25 Correct 11 ms 492 KB Output is correct
26 Correct 11 ms 492 KB Output is correct
27 Correct 16 ms 748 KB Output is correct
28 Correct 15 ms 748 KB Output is correct
29 Correct 16 ms 748 KB Output is correct
30 Correct 23 ms 748 KB Output is correct
31 Correct 21 ms 748 KB Output is correct
32 Correct 21 ms 748 KB Output is correct
33 Correct 165 ms 4460 KB Output is correct
34 Correct 170 ms 4460 KB Output is correct
35 Correct 168 ms 4460 KB Output is correct
36 Correct 257 ms 4460 KB Output is correct
37 Correct 260 ms 4460 KB Output is correct
38 Correct 262 ms 4396 KB Output is correct
39 Correct 164 ms 4460 KB Output is correct
40 Correct 177 ms 4460 KB Output is correct
41 Correct 163 ms 4460 KB Output is correct
42 Correct 130 ms 4460 KB Output is correct
43 Correct 218 ms 4204 KB Output is correct
44 Correct 220 ms 4204 KB Output is correct
45 Correct 218 ms 4204 KB Output is correct
46 Correct 219 ms 4204 KB Output is correct
47 Correct 216 ms 4204 KB Output is correct
48 Correct 216 ms 4204 KB Output is correct
49 Correct 222 ms 4204 KB Output is correct
50 Correct 222 ms 4232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 8 ms 492 KB Output is correct
20 Correct 9 ms 492 KB Output is correct
21 Correct 9 ms 492 KB Output is correct
22 Correct 11 ms 492 KB Output is correct
23 Correct 12 ms 636 KB Output is correct
24 Correct 11 ms 492 KB Output is correct
25 Correct 11 ms 492 KB Output is correct
26 Correct 11 ms 492 KB Output is correct
27 Correct 455 ms 12636 KB Output is correct
28 Correct 460 ms 12396 KB Output is correct
29 Correct 461 ms 12652 KB Output is correct
30 Correct 466 ms 12644 KB Output is correct
31 Correct 354 ms 12780 KB Output is correct
32 Correct 538 ms 13036 KB Output is correct
33 Correct 426 ms 12908 KB Output is correct
34 Correct 430 ms 12908 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 287 ms 4332 KB Output is correct
37 Correct 1068 ms 12396 KB Output is correct
38 Correct 977 ms 12268 KB Output is correct
39 Correct 946 ms 12012 KB Output is correct
40 Correct 375 ms 6508 KB Output is correct
41 Correct 184 ms 3544 KB Output is correct
42 Correct 32 ms 1004 KB Output is correct
43 Correct 966 ms 12268 KB Output is correct
44 Correct 838 ms 12200 KB Output is correct
45 Correct 888 ms 12516 KB Output is correct
46 Correct 862 ms 12840 KB Output is correct
47 Correct 609 ms 12012 KB Output is correct
48 Correct 808 ms 12524 KB Output is correct
49 Correct 902 ms 12672 KB Output is correct
50 Correct 569 ms 12268 KB Output is correct
51 Correct 16 ms 748 KB Output is correct
52 Correct 15 ms 748 KB Output is correct
53 Correct 16 ms 748 KB Output is correct
54 Correct 23 ms 748 KB Output is correct
55 Correct 21 ms 748 KB Output is correct
56 Correct 21 ms 748 KB Output is correct
57 Correct 165 ms 4460 KB Output is correct
58 Correct 170 ms 4460 KB Output is correct
59 Correct 168 ms 4460 KB Output is correct
60 Correct 257 ms 4460 KB Output is correct
61 Correct 260 ms 4460 KB Output is correct
62 Correct 262 ms 4396 KB Output is correct
63 Correct 164 ms 4460 KB Output is correct
64 Correct 177 ms 4460 KB Output is correct
65 Correct 163 ms 4460 KB Output is correct
66 Correct 130 ms 4460 KB Output is correct
67 Correct 218 ms 4204 KB Output is correct
68 Correct 220 ms 4204 KB Output is correct
69 Correct 218 ms 4204 KB Output is correct
70 Correct 219 ms 4204 KB Output is correct
71 Correct 216 ms 4204 KB Output is correct
72 Correct 216 ms 4204 KB Output is correct
73 Correct 222 ms 4204 KB Output is correct
74 Correct 222 ms 4232 KB Output is correct
75 Correct 583 ms 12780 KB Output is correct
76 Correct 530 ms 13036 KB Output is correct
77 Correct 548 ms 12652 KB Output is correct
78 Correct 596 ms 12652 KB Output is correct
79 Correct 650 ms 12792 KB Output is correct
80 Correct 553 ms 12780 KB Output is correct
81 Correct 984 ms 12480 KB Output is correct
82 Correct 983 ms 12396 KB Output is correct
83 Correct 951 ms 12268 KB Output is correct
84 Correct 1000 ms 12320 KB Output is correct
85 Correct 960 ms 12652 KB Output is correct
86 Correct 1032 ms 12344 KB Output is correct
87 Correct 1020 ms 12908 KB Output is correct
88 Correct 613 ms 12780 KB Output is correct
89 Correct 646 ms 12700 KB Output is correct
90 Correct 625 ms 12712 KB Output is correct
91 Correct 602 ms 12712 KB Output is correct
92 Correct 651 ms 12712 KB Output is correct
93 Correct 755 ms 12900 KB Output is correct
94 Correct 736 ms 12852 KB Output is correct
95 Correct 763 ms 12908 KB Output is correct
96 Correct 749 ms 13036 KB Output is correct
97 Correct 943 ms 12908 KB Output is correct
98 Correct 605 ms 12912 KB Output is correct
99 Correct 809 ms 12652 KB Output is correct
100 Correct 763 ms 12352 KB Output is correct
101 Correct 701 ms 12872 KB Output is correct
102 Correct 738 ms 12780 KB Output is correct
103 Correct 876 ms 12908 KB Output is correct
104 Correct 805 ms 12396 KB Output is correct
105 Correct 497 ms 12652 KB Output is correct
106 Correct 733 ms 12524 KB Output is correct
107 Correct 713 ms 12424 KB Output is correct
108 Correct 705 ms 12396 KB Output is correct
109 Correct 719 ms 12412 KB Output is correct
110 Correct 740 ms 12420 KB Output is correct
111 Correct 714 ms 12396 KB Output is correct
112 Correct 714 ms 12412 KB Output is correct
113 Correct 709 ms 12524 KB Output is correct
114 Correct 753 ms 12524 KB Output is correct
115 Correct 711 ms 12524 KB Output is correct
116 Correct 712 ms 12268 KB Output is correct