답안 #955540

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
955540 2024-03-30T21:53:27 Z rainboy Non-boring sequences (CERC12_D) C
1 / 1
480 ms 18164 KB
#include <stdio.h>
#include <string.h>

#define N	200000
#define N_	(1 << 18)	/* N_ = pow2(ceil(log2(N + 1))) */
#define INF	0x3f3f3f3f

int min(int a, int b) { return a < b ? a : b; }

unsigned int X = 12345;

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

int aa[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 = aa[ii[j]] != aa[i_] ? aa[ii[j]] - aa[i_] : 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 ss[N_ * 2], qq[N_ * 2], n_;

void pul(int i) {
	int l = i << 1, r = l | 1;

	ss[i] = ss[l] + ss[r];
	qq[i] = min(qq[l] + ss[r], qq[r]);
}

void build(int n) {
	n_ = 1;
	while (n_ <= n)
		n_ <<= 1;
	memset(ss, 0, n_ * 2 * sizeof *ss);
	memset(qq, 0, n_ * 2 * sizeof *qq);
}

void update(int i, int x) {
	i += n_;
	ss[i] = qq[i] = x;
	while (i > 1)
		pul(i >>= 1);
}

int query(int r) {
	int l, q, s;

	l = 0, q = INF, s = 0;
	for (l += n_, r += n_; l <= r; l >>= 1, r >>= 1)
		if ((r & 1) == 0)
			q = min(qq[r] + s, q), s += ss[r], r--;
	return q;
}

int main() {
	int t;

	scanf("%d", &t);
	while (t--) {
		static int ii[N], pp[N];
		int n, i, boring;

		scanf("%d", &n);
		for (i = 0; i < n; i++)
			scanf("%d", &aa[i]);
		for (i = 0; i < n; i++)
			ii[i] = i;
		sort(ii, 0, n);
		for (i = 0; i < n; i++)
			pp[ii[i]] = i == 0 || aa[ii[i]] != aa[ii[i - 1]] ? -1 : ii[i - 1];
		build(n);
		boring = 0;
		for (i = 0; i < n; i++) {
			update(i, 1);
			if (pp[i] != -1) {
				update(pp[i], -1);
				if (pp[pp[i]] != -1)
					update(pp[pp[i]], 0);
			}
			if (query(i) == 0) {
				boring = 1;
				break;
			}
		}
		printf(boring ? "boring\n" : "non-boring\n");
	}
	return 0;
}

Compilation message

D.c: In function 'main':
D.c:77:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |  scanf("%d", &t);
      |  ^~~~~~~~~~~~~~~
D.c:82:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |   scanf("%d", &n);
      |   ^~~~~~~~~~~~~~~
D.c:84:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |    scanf("%d", &aa[i]);
      |    ^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 5224 KB Output is correct
2 Correct 141 ms 9808 KB Output is correct
3 Correct 143 ms 10024 KB Output is correct
4 Correct 122 ms 9040 KB Output is correct
5 Correct 440 ms 18004 KB Output is correct
6 Correct 480 ms 18164 KB Output is correct
7 Correct 426 ms 16832 KB Output is correct