답안 #769986

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
769986 2023-06-30T15:44:57 Z rainboy Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C
0 / 100
652 ms 29576 KB
#include <stdio.h>

#define N	1000000
#define M	1000000

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

unsigned int X = 12345;

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

int aa[N];
int ll[M], rr[M], bb[M], ans[M];

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)
			if (rr[hh[j]] == rr[h])
				j++;
			else if (rr[hh[j]] < rr[h]) {
				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;
	}
}

int ft[N];

void update(int i, int n, int x) {
	while (i < n) {
		ft[i] = max(ft[i], x);
		i |= i + 1;
	}
}

int query(int i) {
	int x = 0;

	while (i >= 0) {
		x = max(x, ft[i]);
		i &= i + 1, i--;
	}
	return x;
}

int main() {
	static int hh[M], qu[N];
	int n, m, cnt, h, h_, i, j;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	for (h = 0; h < m; h++) {
		scanf("%d%d%d", &ll[h], &rr[h], &bb[h]);
		hh[h] = h;
	}
	sort(hh, 0, m);
	cnt = 0;
	for (h = 0, j = 0; j < n; j++) {
		while (cnt && aa[qu[cnt - 1]] <= aa[j])
			cnt--;
		if (cnt) {
			i = qu[cnt - 1];
			update(n - 1 - i, n, aa[i] + aa[j]);
		}
		while (h < m && rr[h_ = hh[h]] == j) {
			ans[h_] = query(n - 1 - ll[h_]) <= bb[h_];
			h++;
		}
		qu[cnt++] = j;
	}
	for (h = 0; h < m; h++)
		printf("%d\n", ans[h]);
	return 0;
}

Compilation message

sortbooks.c: In function 'main':
sortbooks.c:59:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
sortbooks.c:61:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
sortbooks.c:63:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |   scanf("%d%d%d", &ll[h], &rr[h], &bb[h]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 652 ms 29576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 3148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -