Submission #829665

# Submission time Handle Problem Language Result Execution time Memory
829665 2023-08-18T13:56:13 Z rainboy Curtains (NOI23_curtains) C
100 / 100
406 ms 31664 KB
#include <stdio.h>

#define N	500000
#define K	500000
#define Q	500000
#define N_	(1 << 19)	/* N_ = pow2(ceil(log2(N)) */
#define INF	0x3f3f3f3f

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

int st[N_ * 2], n_, mode;

void build(int *aa, int n) {
	int i;

	n_ = 1;
	while (n_ < n)
		n_ <<= 1;
	for (i = 0; i < n; i++)
		st[n_ + i] = i < n ? aa[i] : (mode == 0 ? INF : -1);
	for (i = n_ - 1; i > 0; i--)
		st[i] = mode == 0 ? min(st[i << 1 | 0], st[i << 1 | 1]) : max(st[i << 1 | 0], st[i << 1 | 1]);
}

int query(int l, int r) {
	int x = mode == 0 ? INF : -1;

	for (l += n_, r += n_; l <= r; l >>= 1, r >>= 1) {
		if ((l & 1) == 1)
			x = mode == 0 ? min(x, st[l]) : max(x, st[l]), l++;
		if ((r & 1) == 0)
			x = mode == 0 ? min(x, st[r]) : max(x, st[r]), r--;
	}
	return x;
}

int ll[K], rr[K];
int ll_[Q], rr_[Q]; char yes[Q];

void solve(int *gg, int k, int *hh, int q, int l, int r) {
	static int ii[N], jj[N], qu[N];
	int m, cnt, g, g_, g1, g2, g3, h, h_, h1, h2, h3, i, j, tmp;

	if (l == r) {
		if (k == 0)
			for (h = 0; h < q; h++)
				yes[hh[h]] = 0;
		return;
	}
	m = (l + r) / 2;
	g1 = g2 = 0, g3 = k;
	while (g2 < g3)
		if (ll[gg[g2]] <= m && m < rr[gg[g2]])
			g2++;
		else if (rr[gg[g2]] <= m) {
			tmp = gg[g1], gg[g1] = gg[g2], gg[g2] = tmp;
			g1++, g2++;
		} else {
			g3--;
			tmp = gg[g2], gg[g2] = gg[g3], gg[g3] = tmp;
		}
	h1 = h2 = 0, h3 = q;
	while (h2 < h3)
		if (ll_[hh[h2]] <= m && m < rr_[hh[h2]])
			h2++;
		else if (rr_[hh[h2]] <= m) {
			tmp = hh[h1], hh[h1] = hh[h2], hh[h2] = tmp;
			h1++, h2++;
		} else {
			h3--;
			tmp = hh[h2], hh[h2] = hh[h3], hh[h3] = tmp;
		}
	for (i = l; i <= m; i++)
		jj[i] = i - 1;
	for (g = 0; g < g1; g++) {
		g_ = gg[g];
		jj[ll[g_]] = max(jj[ll[g_]], rr[g_]);
	}
	cnt = 0;
	for (i = m; i >= l; i--) {
		qu[cnt++] = i;
		while (cnt && qu[cnt - 1] <= jj[i])
			cnt--;
		ii[i] = cnt == 0 ? -1 : qu[cnt - 1];
	}
	for (i = l; i <= m; i++)
		jj[i] = r + 1;
	for (g = g1; g < g2; g++) {
		g_ = gg[g];
		jj[ll[g_]] = min(jj[ll[g_]], rr[g_]);
	}
	mode = 0, build(jj + l, m - l + 1);
	for (h = h1; h < h2; h++) {
		h_ = hh[h];
		if ((i = ii[ll_[h_]]) != -1 && query(ll_[h_] - l, i - l) > rr_[h_])
			yes[h_] = 0;
	}
	for (j = m + 1; j <= r; j++)
		ii[j] = j + 1;
	for (g = g2; g < k; g++) {
		g_ = gg[g];
		ii[rr[g_]] = min(ii[rr[g_]], ll[g_]);
	}
	cnt = 0;
	for (j = m + 1; j <= r; j++) {
		qu[cnt++] = j;
		while (cnt && qu[cnt - 1] >= ii[j])
			cnt--;
		jj[j] = cnt == 0 ? -1 : qu[cnt - 1];
	}
	for (j = m + 1; j <= r; j++)
		ii[j] = l - 1;
	for (g = g1; g < g2; g++) {
		g_ = gg[g];
		ii[rr[g_]] = max(ii[rr[g_]], ll[g_]);
	}
	mode = 1, build(ii + m + 1, r - m);
	for (h = h1; h < h2; h++) {
		h_ = hh[h];
		if ((j = jj[rr_[h_]]) != -1 && query(j - (m + 1), rr_[h_] - (m + 1)) < ll_[h_])
			yes[h_] = 0;
	}
	solve(gg, g1, hh, h1, l, m), solve(gg + g2, k - g2, hh + h2, q - h2, m + 1, r);
}

int main() {
	static int gg[K], hh[Q];
	int n, k, q, g, h;

	scanf("%d%d%d", &n, &k, &q);
	for (g = 0; g < k; g++) {
		scanf("%d%d", &ll[g], &rr[g]), ll[g]--, rr[g]--;
		gg[g] = g;
	}
	for (h = 0; h < q; h++) {
		scanf("%d%d", &ll_[h], &rr_[h]), ll_[h]--, rr_[h]--;
		hh[h] = h;
	}
	for (h = 0; h < q; h++)
		yes[h] = 1;
	solve(gg, k, hh, q, 0, n - 1);
	for (h = 0; h < q; h++)
		printf(yes[h] ? "YES\n" : "NO\n");
	return 0;
}

Compilation message

curtains.c: In function 'main':
curtains.c:131:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  131 |  scanf("%d%d%d", &n, &k, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
curtains.c:133:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  133 |   scanf("%d%d", &ll[g], &rr[g]), ll[g]--, rr[g]--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
curtains.c:137:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  137 |   scanf("%d%d", &ll_[h], &rr_[h]), ll_[h]--, rr_[h]--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 296 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 296 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 1 ms 396 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 296 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 1 ms 396 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 98 ms 12088 KB Output is correct
23 Correct 96 ms 12620 KB Output is correct
24 Correct 98 ms 14620 KB Output is correct
25 Correct 153 ms 22616 KB Output is correct
26 Correct 111 ms 12316 KB Output is correct
27 Correct 168 ms 22348 KB Output is correct
28 Correct 156 ms 22572 KB Output is correct
29 Correct 105 ms 11916 KB Output is correct
30 Correct 93 ms 11448 KB Output is correct
31 Correct 87 ms 12232 KB Output is correct
32 Correct 150 ms 21196 KB Output is correct
33 Correct 79 ms 11724 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 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 90 ms 11428 KB Output is correct
9 Correct 86 ms 12464 KB Output is correct
10 Correct 154 ms 21304 KB Output is correct
11 Correct 82 ms 11304 KB Output is correct
12 Correct 44 ms 6028 KB Output is correct
13 Correct 46 ms 5932 KB Output is correct
14 Correct 67 ms 5900 KB Output is correct
15 Correct 66 ms 6008 KB Output is correct
16 Correct 65 ms 5964 KB Output is correct
17 Correct 63 ms 5904 KB Output is correct
18 Correct 256 ms 23588 KB Output is correct
19 Correct 270 ms 23684 KB Output is correct
20 Correct 360 ms 23464 KB Output is correct
21 Correct 358 ms 23504 KB Output is correct
22 Correct 366 ms 23564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 296 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 1 ms 396 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 34 ms 4944 KB Output is correct
23 Correct 33 ms 5068 KB Output is correct
24 Correct 48 ms 6140 KB Output is correct
25 Correct 48 ms 6332 KB Output is correct
26 Correct 55 ms 6268 KB Output is correct
27 Correct 54 ms 6188 KB Output is correct
28 Correct 55 ms 5300 KB Output is correct
29 Correct 61 ms 6028 KB Output is correct
30 Correct 47 ms 6500 KB Output is correct
31 Correct 49 ms 6376 KB Output is correct
32 Correct 64 ms 6220 KB Output is correct
33 Correct 67 ms 6424 KB Output is correct
34 Correct 49 ms 6264 KB Output is correct
35 Correct 52 ms 5808 KB Output is correct
36 Correct 56 ms 6248 KB Output is correct
37 Correct 44 ms 6092 KB Output is correct
38 Correct 48 ms 6212 KB Output is correct
39 Correct 65 ms 6004 KB Output is correct
40 Correct 64 ms 5484 KB Output is correct
41 Correct 66 ms 5964 KB Output is correct
42 Correct 69 ms 6040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 296 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 1 ms 396 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 98 ms 12088 KB Output is correct
23 Correct 96 ms 12620 KB Output is correct
24 Correct 98 ms 14620 KB Output is correct
25 Correct 153 ms 22616 KB Output is correct
26 Correct 111 ms 12316 KB Output is correct
27 Correct 168 ms 22348 KB Output is correct
28 Correct 156 ms 22572 KB Output is correct
29 Correct 105 ms 11916 KB Output is correct
30 Correct 93 ms 11448 KB Output is correct
31 Correct 87 ms 12232 KB Output is correct
32 Correct 150 ms 21196 KB Output is correct
33 Correct 79 ms 11724 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 90 ms 11428 KB Output is correct
42 Correct 86 ms 12464 KB Output is correct
43 Correct 154 ms 21304 KB Output is correct
44 Correct 82 ms 11304 KB Output is correct
45 Correct 44 ms 6028 KB Output is correct
46 Correct 46 ms 5932 KB Output is correct
47 Correct 67 ms 5900 KB Output is correct
48 Correct 66 ms 6008 KB Output is correct
49 Correct 65 ms 5964 KB Output is correct
50 Correct 63 ms 5904 KB Output is correct
51 Correct 256 ms 23588 KB Output is correct
52 Correct 270 ms 23684 KB Output is correct
53 Correct 360 ms 23464 KB Output is correct
54 Correct 358 ms 23504 KB Output is correct
55 Correct 366 ms 23564 KB Output is correct
56 Correct 34 ms 4944 KB Output is correct
57 Correct 33 ms 5068 KB Output is correct
58 Correct 48 ms 6140 KB Output is correct
59 Correct 48 ms 6332 KB Output is correct
60 Correct 55 ms 6268 KB Output is correct
61 Correct 54 ms 6188 KB Output is correct
62 Correct 55 ms 5300 KB Output is correct
63 Correct 61 ms 6028 KB Output is correct
64 Correct 47 ms 6500 KB Output is correct
65 Correct 49 ms 6376 KB Output is correct
66 Correct 64 ms 6220 KB Output is correct
67 Correct 67 ms 6424 KB Output is correct
68 Correct 49 ms 6264 KB Output is correct
69 Correct 52 ms 5808 KB Output is correct
70 Correct 56 ms 6248 KB Output is correct
71 Correct 44 ms 6092 KB Output is correct
72 Correct 48 ms 6212 KB Output is correct
73 Correct 65 ms 6004 KB Output is correct
74 Correct 64 ms 5484 KB Output is correct
75 Correct 66 ms 5964 KB Output is correct
76 Correct 69 ms 6040 KB Output is correct
77 Correct 259 ms 30796 KB Output is correct
78 Correct 244 ms 30668 KB Output is correct
79 Correct 302 ms 31136 KB Output is correct
80 Correct 304 ms 30308 KB Output is correct
81 Correct 305 ms 29504 KB Output is correct
82 Correct 406 ms 31664 KB Output is correct
83 Correct 249 ms 30436 KB Output is correct
84 Correct 254 ms 31016 KB Output is correct
85 Correct 346 ms 30712 KB Output is correct
86 Correct 277 ms 30156 KB Output is correct
87 Correct 286 ms 29596 KB Output is correct
88 Correct 339 ms 29736 KB Output is correct