Submission #490090

# Submission time Handle Problem Language Result Execution time Memory
490090 2021-11-25T14:09:35 Z rainboy Svjetlost (COI18_svjetlost) C
Compilation error
0 ms 0 KB
#include <math.h>
#include <stdio.h>

#define N	100000
#define M	(N * 8)

double max(double a, double b) { return a > b ? a : b; }

unsigned int X = 12345;

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

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

long long cross(int x1, int y1, int x2, int y2) {
	return (long long) x1 * y2 - (long long) x2 * y1;
}

int xx_[M * 2], yy_[M * 2], hh[M * 2], ii[M * 2], m;

void add(int i, int j) {
	int h = m++;

	xx_[h << 1 | 0] = xx[i] - xx[j], yy_[h << 1 | 0] = yy[i] - yy[j];
	xx_[h << 1 | 1] = xx[j] - xx[i], yy_[h << 1 | 1] = yy[j] - yy[i];
}

int compare(int h1, int h2) {
	int sgn1, sgn2;
	long long c;

	sgn1 = xx_[h1] < 0 || xx_[h1] == 0 && yy_[h1] < 0 ? -1 : 1;
	sgn2 = xx_[h2] < 0 || xx_[h2] == 0 && yy_[h2] < 0 ? -1 : 1;
	if (sgn1 != sgn2)
		return sgn1 - sgn2;
	c = cross(xx_[h1], yy_[h1], xx_[h2], yy_[h2]);
	return c == 0 ? 0 : c < 0 ? -1 : 1;
}

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

		while (j < k) {
			int c = compare(hh[j], h);

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

double aa[M * 2]; int n_;

void update_(int i, double x) {
	aa[i] += x;
}

void update(int h, int w) {
	int h0 = h << 1, h1 = h0 | 1;
	double d = hypot(xx_[h0], yy_[h0]);

	update_(ii[h0], d * w), update_(ii[h1], -d * w);
	if (ii[h0] > ii[h1])
		update_(0, d * w);
}

double query() {
	int i;
	double a, ans;

	a = 0, ans = 0;
	for (i = 0; i < n_; i++)
		ans = max(ans, a += aa[i]);
	return ans;
}

int main() {
	static int uu[N], vv[N];
	int q, h, i;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d%d", &xx[i], &yy[i]);
	for (i = 0; i < n; i++)
		uu[i] = (i - 1 + n) % n, vv[i] = (i + 1) % n;
	for (i = 0; i < n; i++)
		add(i, vv[i]);
	scanf("%d", &q);
	for (h = 0; h < q; h++) {
		int u, v;

		scanf("%d", &i), i--;
		u = uu[i], v = vv[i];
		add(u, i), add(i, v), add(u, v);
		vv[u] = v, uu[v] = u;
	}
	for (h = 0; h < m * 2; h++)
		hh[h] = h;
	sort(hh, 0, m * 2);
	for (h = 0, n_ = 0; h < m * 2; h++)
		ii[hh[h]] = h + 1 == m * 2 || compare(hh[h + 1], hh[h]) != 0 ? n_++ : n_;
	for (h = 0; h < n; h++)
		update(h, 1);
	printf("%f\n", query());
	for (h = 0; h < q; h++) {
		update(n + h * 3 + 0, -1), update(n + h * 3 + 1, -1), update(n + h * 3 + 2, 1);
		printf("%f\n", query());
	}
	return 0;
}

Compilation message

svjetlost.c: In function 'compare':
svjetlost.c:34:37: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   34 |  sgn1 = xx_[h1] < 0 || xx_[h1] == 0 && yy_[h1] < 0 ? -1 : 1;
      |                        ~~~~~~~~~~~~~^~~~~~~~~~~~~~
svjetlost.c:35:37: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   35 |  sgn2 = xx_[h2] < 0 || xx_[h2] == 0 && yy_[h2] < 0 ? -1 : 1;
      |                        ~~~~~~~~~~~~~^~~~~~~~~~~~~~
svjetlost.c: In function 'main':
svjetlost.c:93:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
svjetlost.c:95:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |   scanf("%d%d", &xx[i], &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
svjetlost.c:100:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |  scanf("%d", &q);
      |  ^~~~~~~~~~~~~~~
svjetlost.c:104:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |   scanf("%d", &i), i--;
      |   ^~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cciy5Gfx.o: in function `update':
svjetlost.c:(.text+0x2e8): undefined reference to `hypot'
collect2: error: ld returned 1 exit status