제출 #716349

#제출 시각아이디문제언어결과실행 시간메모리
716349rainboyFinancial Report (JOI21_financial)C11
5 / 100
186 ms13420 KiB
#include <stdio.h>
#include <string.h>

#define N	300000
#define N_	(1 << 19)	/* N_ = pow2(ceil(log2(N))) */

int max(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_] : i_ - ii[j];

			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 st[N_ * 2], n_;

void update(int i, int x) {
	for (i += n_; i > 0; i >>= 1)
		st[i] = max(st[i], x);
}

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

	for (l += n_, r += n_; 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;
}

int main() {
	static int ii[N], prev[N], next[N], ll[N];
	int n, d, h, i, p, q;

	scanf("%d%d", &n, &d);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	for (i = 0; i < n; i++)
		ii[i] = i;
	sort(ii, 0, n);
	n_ = 1;
	while (n_ < n)
		n_ <<= 1;
	memset(st, -1, n_ * 2 * sizeof *st);
	for (i = 0; i < n; i++)
		prev[i] = i - 1, next[i] = i + 1;
	for (h = n - 1; h >= 0; h--) {
		i = ii[h], p = prev[i], q = next[i];
		ll[i] = query(0, i - 1) + 1;
		if (p != -1)
			next[p] = q;
		if (q != n)
			prev[q] = p;
		if (q - p - 1 >= d)
			update(q - 1, 1);
	}
	memset(st, 0, n_ * 2 * sizeof *st);
	for (h = 0; h < n; h++) {
		i = ii[h];
		update(i, query(ll[i], i) + 1);
	}
	printf("%d\n", query(0, n - 1));
	return 0;
}

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

Main.c: In function 'main':
Main.c:62:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |  scanf("%d%d", &n, &d);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:64:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |   scanf("%d", &aa[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...