제출 #381277

#제출 시각아이디문제언어결과실행 시간메모리
381277rainboyCircle selection (APIO18_circle_selection)C11
23 / 100
2665 ms24628 KiB
#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];

int intersect(int i, int j) {
	long long x = xx[i] - xx[j], y = yy[i] - yy[j], r = rr[i] + rr[j];

	return x * x + y * y <= r * r;
}

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], 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]] >> lg + 1, y_ = yy[ii_[i]] >> lg + 1;

		if (x_ < x || x_ == x && y_ <= y)
			lower = i;
		else
			upper = i;
	}
	return lower != -1 && xx[ii_[lower]] >> lg + 1 == x && yy[ii_[lower]] >> lg + 1 == y ? lower : -1;
}

int main() {
	static char root[N];
	static int iii[N][4], kk[N], ii[N], tmp[N], pp[N];
	int g, 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);
	for (lg = 30, h = 0; lg >= 0; lg--) {
		memset(kk, 0, n * sizeof *kk);
		for (i = n - 1, j = n - 1; i >= 0; i--) {
			if (xx[ii_[i]] >> lg + 1 != xx[ii_[j]] >> lg + 1 || yy[ii_[i]] >> lg + 1 != yy[ii_[j]] >> lg + 1)
				j = i;
			if (root[ii_[i]])
				iii[j][kk[j]++] = ii_[i];
		}
		while (h < n && rr[ii[h]] >= 1 << lg) {
			int i_ = ii[h], x = xx[i_] >> lg + 1, y = yy[i_] >> lg + 1, dx, dy, p;

			p = -1;
			for (dx = -2; dx <= 2; dx++)
				for (dy = -2; dy <= 2; dy++) {
					g = idx(x + dx, y + dy);
					for (h_ = 0; h_ < kk[g]; h_++) {
						int j_ = iii[g][h_];

						if (intersect(i_, j_) && (p == -1 || rr[p] < rr[j_] || rr[p] == rr[j_] && p > j_))
							p = j_;
					}
				}
			if (p != -1)
				pp[i_] = p;
			else {
				pp[i_] = i_, root[i_] = 1;
				g = idx(x, y);
				iii[g][kk[g]++] = i_;
			}
			h++;
		}
		for (i = 0; i < n; i = j) {
			int x = xx[ii_[i]] >> lg + 1;

			j = i + 1;
			while (j < n && (xx[ii_[j]] >> lg + 1) == x)
				j++;
			cnt = 0;
			for (h_ = i; h_ < j; h_++)
				if ((xx[ii_[h_]] >> lg & 1) == 0)
					ii_[i++] = ii_[h_];
				else
					tmp[cnt++] = ii_[h_];
			memcpy(ii_ + i, tmp, cnt * sizeof *tmp);
		}
		for (i = 0; i < n; i = j) {
			int x = xx[ii_[i]] >> lg, y = yy[ii_[i]] >> lg + 1;

			j = i + 1;
			while (j < n && (xx[ii_[j]] >> lg) == x && (yy[ii_[j]] >> lg + 1) == y)
				j++;
			cnt = 0;
			for (h_ = i; h_ < j; h_++)
				if ((yy[ii_[h_]] >> lg & 1) == 0)
					ii_[i++] = ii_[h_];
				else
					tmp[cnt++] = ii_[h_];
			memcpy(ii_ + i, tmp, cnt * sizeof *tmp);
		}
	}
	for (i = 0; i < n; i++)
		printf("%d ", pp[i] + 1);
	printf("\n");
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

circle_selection.c: In function 'idx':
circle_selection.c:49:54: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |   int i = (lower + upper) / 2, x_ = xx[ii_[i]] >> lg + 1, y_ = yy[ii_[i]] >> lg + 1;
      |                                                   ~~~^~~
circle_selection.c:49:81: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |   int i = (lower + upper) / 2, x_ = xx[ii_[i]] >> lg + 1, y_ = yy[ii_[i]] >> lg + 1;
      |                                                                              ~~~^~~
circle_selection.c:51:25: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   51 |   if (x_ < x || x_ == x && y_ <= y)
      |                 ~~~~~~~~^~~~~~~~~~
circle_selection.c:56:45: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   56 |  return lower != -1 && xx[ii_[lower]] >> lg + 1 == x && yy[ii_[lower]] >> lg + 1 == y ? lower : -1;
      |                                          ~~~^~~
circle_selection.c:56:78: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   56 |  return lower != -1 && xx[ii_[lower]] >> lg + 1 == x && yy[ii_[lower]] >> lg + 1 == y ? lower : -1;
      |                                                                           ~~~^~~
circle_selection.c: In function 'main':
circle_selection.c:74:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   74 |    if (xx[ii_[i]] >> lg + 1 != xx[ii_[j]] >> lg + 1 || yy[ii_[i]] >> lg + 1 != yy[ii_[j]] >> lg + 1)
      |                      ~~~^~~
circle_selection.c:74:49: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   74 |    if (xx[ii_[i]] >> lg + 1 != xx[ii_[j]] >> lg + 1 || yy[ii_[i]] >> lg + 1 != yy[ii_[j]] >> lg + 1)
      |                                              ~~~^~~
circle_selection.c:74:73: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   74 |    if (xx[ii_[i]] >> lg + 1 != xx[ii_[j]] >> lg + 1 || yy[ii_[i]] >> lg + 1 != yy[ii_[j]] >> lg + 1)
      |                                                                      ~~~^~~
circle_selection.c:74:97: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   74 |    if (xx[ii_[i]] >> lg + 1 != xx[ii_[j]] >> lg + 1 || yy[ii_[i]] >> lg + 1 != yy[ii_[j]] >> lg + 1)
      |                                                                                              ~~~^~~
circle_selection.c:80:37: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   80 |    int i_ = ii[h], x = xx[i_] >> lg + 1, y = yy[i_] >> lg + 1, dx, dy, p;
      |                                  ~~~^~~
circle_selection.c:80:59: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   80 |    int i_ = ii[h], x = xx[i_] >> lg + 1, y = yy[i_] >> lg + 1, dx, dy, p;
      |                                                        ~~~^~~
circle_selection.c:89:78: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   89 |       if (intersect(i_, j_) && (p == -1 || rr[p] < rr[j_] || rr[p] == rr[j_] && p > j_))
      |                                                              ~~~~~~~~~~~~~~~~^~~~~~~~~
circle_selection.c:103:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  103 |    int x = xx[ii_[i]] >> lg + 1;
      |                          ~~~^~~
circle_selection.c:106:38: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  106 |    while (j < n && (xx[ii_[j]] >> lg + 1) == x)
      |                                   ~~~^~~
circle_selection.c:117:51: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  117 |    int x = xx[ii_[i]] >> lg, y = yy[ii_[i]] >> lg + 1;
      |                                                ~~~^~~
circle_selection.c:120:65: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  120 |    while (j < n && (xx[ii_[j]] >> lg) == x && (yy[ii_[j]] >> lg + 1) == y)
      |                                                              ~~~^~~
circle_selection.c:64:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   64 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
circle_selection.c:66:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   66 |   scanf("%d%d%d", &xx[i], &yy[i], &rr[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...