Submission #477105

# Submission time Handle Problem Language Result Execution time Memory
477105 2021-09-30T13:16:02 Z rainboy Sunčanje (COCI18_suncanje) C
130 / 130
2023 ms 9924 KB
#include <stdio.h>
#include <string.h>

#define N	100000
#define N_	(1 << 18)	/* N_ = pow2(ceil(log2(N * 2))) */

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

unsigned int X = 12345;

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

int *zz;

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) {
			if (zz[ii[j]] == zz[i_])
				j++;
			else if (zz[ii[j]] < zz[i_]) {
				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;
	}
}

void compress(int *xx, int n) {
	static int ii[N * 2];
	int i, x;

	for (i = 0; i < n; i++)
		ii[i] = i;
	zz = xx, sort(ii, 0, n);
	for (i = 0, x = 0; i < n; i++)
		xx[ii[i]] = i + 1 == n || xx[ii[i + 1]] != xx[ii[i]] ? x++ : x;
}

int st[N_ * 2], lz[N_], h_, n_;

void put(int i, int x) {
	st[i] = max(st[i], x);
	if (i < n_)
		lz[i] = max(lz[i], x);
}

void pus(int i) {
	if (lz[i] != -1)
		put(i << 1 | 0, lz[i]), put(i << 1 | 1, lz[i]), lz[i] = -1;
}

void pul(int i) {
	if (lz[i] == -1)
		st[i] = max(st[i << 1 | 0], st[i << 1 | 1]);
}

void push(int i) {
	int h;

	for (h = h_; h > 0; h--)
		pus(i >> h);
}

void pull(int i) {
	while (i > 1)
		pul(i >>= 1);
}

void update(int l, int r, int x) {
	int l_ = l += n_, r_ = r += n_;

	push(l_), push(r_);
	for ( ; l <= r; l >>= 1, r >>= 1) {
		if ((l & 1) == 1)
			put(l++, x);
		if ((r & 1) == 0)
			put(r--, x);
	}
	pull(l_), pull(r_);
}

int query(int l, int r) {
	int x = -1;

	push(l += n_), push(r += n_);
	for ( ; l <= r; l >>= 1, r >>= 1) {
		if ((l & 1) == 1)
			x = max(x, st[l++]);
		if ((r & 1) == 0)
			x = max(x, st[r--]);
	}
	return x;
}

void clean(int i) {
	if (st[i] == -1)
		return;
	st[i] = -1;
	if (i < n_)
		lz[i] = -1, clean(i << 1 | 0), clean(i << 1 | 1);
}

int xx[N * 2], yy[N * 2], mx[N];

void solve(int *ii, int n, int xl, int xr) {
	int i, i1, i2, i3, tmp;

	i1 = 0, i2 = 0, i3 = n;
	while (i2 < i3)
		if (xx[ii[i2] << 1 | 0] <= xl && xr <= xx[ii[i2] << 1 | 1])
			i2++;
		else if (xx[ii[i2] << 1 | 1] > xl && xr > xx[ii[i2] << 1 | 0]) {
			tmp = ii[i1], ii[i1] = ii[i2], ii[i2] = tmp;
			i1++, i2++;
		} else {
			i3--;
			tmp = ii[i2], ii[i2] = ii[i3], ii[i3] = tmp;
		}
	for (i = i1; i < i2; i++)
		update(yy[ii[i] << 1 | 0], yy[ii[i] << 1 | 1] - 1, ii[i]);
	for (i = 0; i < i2; i++)
		mx[ii[i]] = max(mx[ii[i]], query(yy[ii[i] << 1 | 0], yy[ii[i] << 1 | 1] - 1));
	clean(1);
	for (i = 0; i < i1; i++)
		update(yy[ii[i] << 1 | 0], yy[ii[i] << 1 | 1] - 1, ii[i]);
	for (i = i1; i < i2; i++)
		mx[ii[i]] = max(mx[ii[i]], query(yy[ii[i] << 1 | 0], yy[ii[i] << 1 | 1] - 1));
	clean(1);
	if (xr - xl > 1) {
		int xm = (xl + xr) / 2;

		solve(ii, i1, xl, xm), solve(ii, i1, xm, xr);
	}
}

int main() {
	static int ii[N];
	int n, i;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d%d%d%d", &xx[i << 1 | 0], &yy[i << 1 | 0], &xx[i << 1 | 1], &yy[i << 1 | 1]);
		xx[i << 1 | 1] += xx[i << 1 | 0], yy[i << 1 | 1] += yy[i << 1 | 0];
	}
	compress(xx, n * 2);
	compress(yy, n * 2);
	for (i = 0; i < n; i++)
		ii[i] = i;
	h_ = 0;
	while (1 << h_ < n * 2)
		h_++;
	n_ = 1 << h_;
	memset(st, -1, n_ * 2 * sizeof *st), memset(lz, -1, n_ * sizeof *lz);
	memset(mx, -1, n * sizeof *mx);
	solve(ii, n, 0, n * 2);
	for (i = 0; i < n; i++)
		printf(mx[i] <= i ? "DA\n" : "NE\n");
	return 0;
}

Compilation message

suncanje.c: In function 'main':
suncanje.c:149:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  149 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
suncanje.c:151:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  151 |   scanf("%d%d%d%d", &xx[i << 1 | 0], &yy[i << 1 | 0], &xx[i << 1 | 1], &yy[i << 1 | 1]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 40 ms 588 KB Output is correct
2 Correct 57 ms 932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 184 ms 1064 KB Output is correct
2 Correct 559 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 350 ms 1748 KB Output is correct
2 Correct 685 ms 5416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 512 ms 2052 KB Output is correct
2 Correct 515 ms 4868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 851 ms 3476 KB Output is correct
2 Correct 952 ms 5700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 874 ms 3528 KB Output is correct
2 Correct 810 ms 5388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 585 ms 3512 KB Output is correct
2 Correct 1380 ms 6160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 951 ms 5756 KB Output is correct
2 Correct 1024 ms 3588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1436 ms 5948 KB Output is correct
2 Correct 1235 ms 8392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2023 ms 6640 KB Output is correct
2 Correct 1629 ms 9924 KB Output is correct