제출 #695020

#제출 시각아이디문제언어결과실행 시간메모리
695020rainboySushi (JOI16_sushi)C11
20 / 100
92 ms9608 KiB
#include <stdio.h>

#define N	400000

int aa[N], iq[N + 1], pq[N], cnt;

int lt(int i, int j) { return aa[i] > aa[j]; }

int p2(int p) {
	return (p *= 2) > cnt ? 0 : (p < cnt && lt(iq[p + 1], iq[p]) ? p + 1 : p);
}

void pq_up(int i) {
	int p, q, j;

	for (p = pq[i]; (q = p / 2) && lt(i, j = iq[q]); p = q)
		iq[pq[j] = p] = j;
	iq[pq[i] = p] = i;
}

void pq_dn(int i) {
	int p, q, j;

	for (p = pq[i]; (q = p2(p)) && lt(j = iq[q], i); p = q)
		iq[pq[j] = p] = j;
	iq[pq[i] = p] = i;
}

int pq_first() {
	return iq[1];
}

int main() {
	int n, q, h, i;

	scanf("%d%d", &n, &q);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	if (n <= 2000 && q <= 2000) {
		while (q--) {
			int s, t, a, tmp;

			scanf("%d%d%d", &s, &t, &a), s--, t--;
			if (s <= t) {
				for (i = s; i <= t; i++)
					if (a < aa[i])
						tmp = a, a = aa[i], aa[i] = tmp;
			} else {
				for (i = s; i < n; i++)
					if (a < aa[i])
						tmp = a, a = aa[i], aa[i] = tmp;
				for (i = 0; i <= t; i++)
					if (a < aa[i])
						tmp = a, a = aa[i], aa[i] = tmp;
			}
			printf("%d\n", a);
		}
	} else {
		for (i = 0; i < n; i++)
			iq[pq[i] = ++cnt] = i;
		for (h = cnt / 2; h > 0; h--)
			pq_dn(iq[h]);
		while (q--) {
			int a;

			scanf("%*d%*d%d", &a);
			i = pq_first();
			if (aa[i] > a)
				printf("%d\n", aa[i]), aa[i] = a, pq_dn(i);
			else
				printf("%d\n", a);
		}
	}
	return 0;
}

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

sushi.c: In function 'main':
sushi.c:36:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  scanf("%d%d", &n, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~
sushi.c:38:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
sushi.c:43:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |    scanf("%d%d%d", &s, &t, &a), s--, t--;
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
sushi.c:66:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |    scanf("%*d%*d%d", &a);
      |    ^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...