Submission #769989

# Submission time Handle Problem Language Result Execution time Memory
769989 2023-06-30T15:47:31 Z rainboy Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C
100 / 100
783 ms 63308 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]), ll[h]--, rr[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]);
		}
		qu[cnt++] = j;
		while (h < m && rr[h_ = hh[h]] == j) {
			ans[h_] = query(n - 1 - ll[h_]) <= bb[h_];
			h++;
		}
	}
	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]), ll[h]--, rr[h]--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 536 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 3 ms 564 KB Output is correct
15 Correct 3 ms 640 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 621 ms 29636 KB Output is correct
2 Correct 653 ms 29744 KB Output is correct
3 Correct 621 ms 29716 KB Output is correct
4 Correct 640 ms 29804 KB Output is correct
5 Correct 546 ms 25864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 3240 KB Output is correct
2 Correct 54 ms 5156 KB Output is correct
3 Correct 43 ms 4792 KB Output is correct
4 Correct 44 ms 4812 KB Output is correct
5 Correct 45 ms 4812 KB Output is correct
6 Correct 38 ms 4824 KB Output is correct
7 Correct 38 ms 4708 KB Output is correct
8 Correct 40 ms 4556 KB Output is correct
9 Correct 27 ms 3760 KB Output is correct
10 Correct 40 ms 4584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 536 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 3 ms 564 KB Output is correct
15 Correct 3 ms 640 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 560 KB Output is correct
19 Correct 108 ms 12816 KB Output is correct
20 Correct 111 ms 12788 KB Output is correct
21 Correct 106 ms 12584 KB Output is correct
22 Correct 97 ms 12592 KB Output is correct
23 Correct 102 ms 12540 KB Output is correct
24 Correct 94 ms 11744 KB Output is correct
25 Correct 89 ms 11640 KB Output is correct
26 Correct 103 ms 11852 KB Output is correct
27 Correct 95 ms 11856 KB Output is correct
28 Correct 95 ms 11940 KB Output is correct
29 Correct 101 ms 11980 KB Output is correct
30 Correct 101 ms 11936 KB Output is correct
31 Correct 100 ms 11960 KB Output is correct
32 Correct 99 ms 12008 KB Output is correct
33 Correct 125 ms 11940 KB Output is correct
34 Correct 84 ms 11636 KB Output is correct
35 Correct 84 ms 11596 KB Output is correct
36 Correct 84 ms 11464 KB Output is correct
37 Correct 90 ms 11432 KB Output is correct
38 Correct 83 ms 11712 KB Output is correct
39 Correct 90 ms 10868 KB Output is correct
40 Correct 75 ms 9596 KB Output is correct
41 Correct 92 ms 10224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 536 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 3 ms 564 KB Output is correct
15 Correct 3 ms 640 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 560 KB Output is correct
19 Correct 621 ms 29636 KB Output is correct
20 Correct 653 ms 29744 KB Output is correct
21 Correct 621 ms 29716 KB Output is correct
22 Correct 640 ms 29804 KB Output is correct
23 Correct 546 ms 25864 KB Output is correct
24 Correct 46 ms 3240 KB Output is correct
25 Correct 54 ms 5156 KB Output is correct
26 Correct 43 ms 4792 KB Output is correct
27 Correct 44 ms 4812 KB Output is correct
28 Correct 45 ms 4812 KB Output is correct
29 Correct 38 ms 4824 KB Output is correct
30 Correct 38 ms 4708 KB Output is correct
31 Correct 40 ms 4556 KB Output is correct
32 Correct 27 ms 3760 KB Output is correct
33 Correct 40 ms 4584 KB Output is correct
34 Correct 108 ms 12816 KB Output is correct
35 Correct 111 ms 12788 KB Output is correct
36 Correct 106 ms 12584 KB Output is correct
37 Correct 97 ms 12592 KB Output is correct
38 Correct 102 ms 12540 KB Output is correct
39 Correct 94 ms 11744 KB Output is correct
40 Correct 89 ms 11640 KB Output is correct
41 Correct 103 ms 11852 KB Output is correct
42 Correct 95 ms 11856 KB Output is correct
43 Correct 95 ms 11940 KB Output is correct
44 Correct 101 ms 11980 KB Output is correct
45 Correct 101 ms 11936 KB Output is correct
46 Correct 100 ms 11960 KB Output is correct
47 Correct 99 ms 12008 KB Output is correct
48 Correct 125 ms 11940 KB Output is correct
49 Correct 84 ms 11636 KB Output is correct
50 Correct 84 ms 11596 KB Output is correct
51 Correct 84 ms 11464 KB Output is correct
52 Correct 90 ms 11432 KB Output is correct
53 Correct 83 ms 11712 KB Output is correct
54 Correct 90 ms 10868 KB Output is correct
55 Correct 75 ms 9596 KB Output is correct
56 Correct 92 ms 10224 KB Output is correct
57 Correct 695 ms 63280 KB Output is correct
58 Correct 783 ms 63308 KB Output is correct
59 Correct 698 ms 63144 KB Output is correct
60 Correct 676 ms 63136 KB Output is correct
61 Correct 702 ms 63248 KB Output is correct
62 Correct 693 ms 63128 KB Output is correct
63 Correct 493 ms 57384 KB Output is correct
64 Correct 496 ms 57328 KB Output is correct
65 Correct 594 ms 59200 KB Output is correct
66 Correct 574 ms 59216 KB Output is correct
67 Correct 581 ms 59300 KB Output is correct
68 Correct 615 ms 59476 KB Output is correct
69 Correct 573 ms 59284 KB Output is correct
70 Correct 569 ms 59292 KB Output is correct
71 Correct 577 ms 59332 KB Output is correct
72 Correct 580 ms 59336 KB Output is correct
73 Correct 471 ms 55864 KB Output is correct
74 Correct 530 ms 56828 KB Output is correct
75 Correct 480 ms 55820 KB Output is correct
76 Correct 499 ms 55928 KB Output is correct
77 Correct 493 ms 56060 KB Output is correct
78 Correct 527 ms 54460 KB Output is correct
79 Correct 427 ms 46492 KB Output is correct
80 Correct 504 ms 50436 KB Output is correct