#include <stdio.h>
#include <stdlib.h>
#define N 500005
int n, m, q, *eh[N], eo[N], *eh_[N], eo_[N], ii[N], ii_[N], ans[N], I[N], qr[N], ql[N];
void pus(int **eh, int *eo, int i, int j) {
int o = eo[i]++;
if (!o) eh[i] = (int*)malloc(2 * sizeof **eh);
else if (!(o & (o - 1))) eh[i] = (int*)realloc(eh[i], 2 * o * sizeof **eh);
eh[i][o] = j;
}
int cmpr(const void *i, const void *j) {
return *(const int*)i - *(const int*)j;
}
void dnc(int x, int y, int *a, int q) {
if (x > y)
return;
int *al = 0, *ar = 0, ao = 0, ao_ = 0, m = (x + y) / 2;
for (int i = 0; i < q; ++i)
if (qr[a[i]] < m)
pus(&al, &ao, 0, a[i]);
dnc(x, m - 1, al, ao);
free(al);
static int closeL[N], closeR[N], stk[N], sz;
sz = 0;
for (int i = m; i >= x; --i) {
while (eh[i][ii[i] + 1] < m) ++ii[i];
int opt = eh[i][ii[i] + 1], rr = eh[i][ii[i]];
for (; sz && stk[sz] <= rr + 1; --sz)
if (opt > closeL[stk[sz]])
opt = closeL[stk[sz]];
stk[++sz] = i;
closeL[i] = opt;
}
sz = 0;
for (int i = m; i <= y; ++i) {
while (eh_[i][ii_[i] + 1] <= m) ++ii_[i];
int opt = eh_[i][ii_[i]], ll = eh_[i][ii_[i] + 1];
for (; sz && stk[sz] >= ll - 1; --sz)
if (opt < closeR[stk[sz]])
opt = closeR[stk[sz]];
stk[++sz] = i;
closeR[i] = opt;
}
for (int i = 0; i < q; ++i) {
int l = ql[a[i]], r = qr[a[i]];
if (l <= m && m <= r)
ans[a[i]] = closeL[l] <= r && closeR[r] >= l;
else if (l > m)
pus(&ar, &ao_, 0, a[i]);
}
dnc(m + 1, y, ar, ao_);
free(ar);
}
int main() {
scanf("%d%d%d", &n, &m, &q);
for (int i = m, l, r; i--;)
scanf("%d%d", &l, &r),
pus(eh, eo, l, r),
pus(eh_, eo_, r, l);
for (int i = 1; i <= n; ++i)
pus(eh, eo, i, i - 1),
pus(eh, eo, i, N + 1),
pus(eh_, eo_, i, i + 1),
pus(eh_, eo_, i, 0),
qsort(eh[i], eo[i], sizeof **eh, cmpr),
qsort(eh_[i], eo_[i], sizeof **eh_, cmpr);
for (int i = 0; i < q; ++i)
scanf("%d%d", ql + i, qr + i), I[i] = i;
dnc(1, n, I, q);
for (int i = 0; i < q; ++i)
puts(ans[i]? "YES": "NO");
}
Compilation message
curtains.c: In function 'main':
curtains.c:70:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | scanf("%d%d%d", &n, &m, &q);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
curtains.c:72:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | scanf("%d%d", &l, &r),
| ^~~~~~~~~~~~~~~~~~~~~
curtains.c:85:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | scanf("%d%d", ql + i, qr + i), I[i] = i;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14672 KB |
Output is correct |
2 |
Correct |
2 ms |
14672 KB |
Output is correct |
3 |
Correct |
2 ms |
14672 KB |
Output is correct |
4 |
Correct |
2 ms |
14672 KB |
Output is correct |
5 |
Correct |
3 ms |
14928 KB |
Output is correct |
6 |
Correct |
2 ms |
14672 KB |
Output is correct |
7 |
Correct |
3 ms |
14672 KB |
Output is correct |
8 |
Correct |
3 ms |
14672 KB |
Output is correct |
9 |
Correct |
2 ms |
14812 KB |
Output is correct |
10 |
Correct |
2 ms |
14672 KB |
Output is correct |
11 |
Correct |
2 ms |
14672 KB |
Output is correct |
12 |
Correct |
2 ms |
14672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14672 KB |
Output is correct |
2 |
Correct |
2 ms |
14672 KB |
Output is correct |
3 |
Correct |
2 ms |
14672 KB |
Output is correct |
4 |
Correct |
2 ms |
14672 KB |
Output is correct |
5 |
Correct |
3 ms |
14928 KB |
Output is correct |
6 |
Correct |
2 ms |
14672 KB |
Output is correct |
7 |
Correct |
3 ms |
14672 KB |
Output is correct |
8 |
Correct |
3 ms |
14672 KB |
Output is correct |
9 |
Correct |
2 ms |
14812 KB |
Output is correct |
10 |
Correct |
2 ms |
14672 KB |
Output is correct |
11 |
Correct |
2 ms |
14672 KB |
Output is correct |
12 |
Correct |
2 ms |
14672 KB |
Output is correct |
13 |
Correct |
4 ms |
14928 KB |
Output is correct |
14 |
Correct |
3 ms |
14928 KB |
Output is correct |
15 |
Correct |
3 ms |
14928 KB |
Output is correct |
16 |
Correct |
4 ms |
15104 KB |
Output is correct |
17 |
Correct |
3 ms |
14928 KB |
Output is correct |
18 |
Correct |
3 ms |
10832 KB |
Output is correct |
19 |
Correct |
3 ms |
12880 KB |
Output is correct |
20 |
Correct |
4 ms |
14944 KB |
Output is correct |
21 |
Correct |
5 ms |
14928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14672 KB |
Output is correct |
2 |
Correct |
2 ms |
14672 KB |
Output is correct |
3 |
Correct |
2 ms |
14672 KB |
Output is correct |
4 |
Correct |
2 ms |
14672 KB |
Output is correct |
5 |
Correct |
3 ms |
14928 KB |
Output is correct |
6 |
Correct |
2 ms |
14672 KB |
Output is correct |
7 |
Correct |
3 ms |
14672 KB |
Output is correct |
8 |
Correct |
3 ms |
14672 KB |
Output is correct |
9 |
Correct |
2 ms |
14812 KB |
Output is correct |
10 |
Correct |
2 ms |
14672 KB |
Output is correct |
11 |
Correct |
2 ms |
14672 KB |
Output is correct |
12 |
Correct |
2 ms |
14672 KB |
Output is correct |
13 |
Correct |
4 ms |
14928 KB |
Output is correct |
14 |
Correct |
3 ms |
14928 KB |
Output is correct |
15 |
Correct |
3 ms |
14928 KB |
Output is correct |
16 |
Correct |
4 ms |
15104 KB |
Output is correct |
17 |
Correct |
3 ms |
14928 KB |
Output is correct |
18 |
Correct |
3 ms |
10832 KB |
Output is correct |
19 |
Correct |
3 ms |
12880 KB |
Output is correct |
20 |
Correct |
4 ms |
14944 KB |
Output is correct |
21 |
Correct |
5 ms |
14928 KB |
Output is correct |
22 |
Correct |
98 ms |
18284 KB |
Output is correct |
23 |
Correct |
92 ms |
21856 KB |
Output is correct |
24 |
Correct |
114 ms |
22876 KB |
Output is correct |
25 |
Correct |
210 ms |
25360 KB |
Output is correct |
26 |
Correct |
95 ms |
22776 KB |
Output is correct |
27 |
Correct |
203 ms |
32216 KB |
Output is correct |
28 |
Correct |
223 ms |
32272 KB |
Output is correct |
29 |
Correct |
81 ms |
23236 KB |
Output is correct |
30 |
Correct |
79 ms |
18720 KB |
Output is correct |
31 |
Correct |
81 ms |
19412 KB |
Output is correct |
32 |
Correct |
190 ms |
24864 KB |
Output is correct |
33 |
Correct |
80 ms |
21604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12624 KB |
Output is correct |
2 |
Correct |
2 ms |
12624 KB |
Output is correct |
3 |
Correct |
1 ms |
6480 KB |
Output is correct |
4 |
Correct |
2 ms |
6480 KB |
Output is correct |
5 |
Correct |
5 ms |
12880 KB |
Output is correct |
6 |
Correct |
4 ms |
14928 KB |
Output is correct |
7 |
Correct |
4 ms |
14928 KB |
Output is correct |
8 |
Correct |
91 ms |
18652 KB |
Output is correct |
9 |
Correct |
84 ms |
19384 KB |
Output is correct |
10 |
Correct |
203 ms |
24612 KB |
Output is correct |
11 |
Correct |
74 ms |
21528 KB |
Output is correct |
12 |
Correct |
58 ms |
25988 KB |
Output is correct |
13 |
Correct |
60 ms |
27748 KB |
Output is correct |
14 |
Correct |
66 ms |
25764 KB |
Output is correct |
15 |
Correct |
64 ms |
25752 KB |
Output is correct |
16 |
Correct |
65 ms |
24020 KB |
Output is correct |
17 |
Correct |
64 ms |
25888 KB |
Output is correct |
18 |
Correct |
392 ms |
63116 KB |
Output is correct |
19 |
Correct |
452 ms |
71724 KB |
Output is correct |
20 |
Correct |
461 ms |
70984 KB |
Output is correct |
21 |
Correct |
469 ms |
71308 KB |
Output is correct |
22 |
Correct |
397 ms |
68452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14672 KB |
Output is correct |
2 |
Correct |
2 ms |
14672 KB |
Output is correct |
3 |
Correct |
2 ms |
14672 KB |
Output is correct |
4 |
Correct |
2 ms |
14672 KB |
Output is correct |
5 |
Correct |
3 ms |
14928 KB |
Output is correct |
6 |
Correct |
2 ms |
14672 KB |
Output is correct |
7 |
Correct |
3 ms |
14672 KB |
Output is correct |
8 |
Correct |
3 ms |
14672 KB |
Output is correct |
9 |
Correct |
2 ms |
14812 KB |
Output is correct |
10 |
Correct |
2 ms |
14672 KB |
Output is correct |
11 |
Correct |
2 ms |
14672 KB |
Output is correct |
12 |
Correct |
2 ms |
14672 KB |
Output is correct |
13 |
Correct |
4 ms |
14928 KB |
Output is correct |
14 |
Correct |
3 ms |
14928 KB |
Output is correct |
15 |
Correct |
3 ms |
14928 KB |
Output is correct |
16 |
Correct |
4 ms |
15104 KB |
Output is correct |
17 |
Correct |
3 ms |
14928 KB |
Output is correct |
18 |
Correct |
3 ms |
10832 KB |
Output is correct |
19 |
Correct |
3 ms |
12880 KB |
Output is correct |
20 |
Correct |
4 ms |
14944 KB |
Output is correct |
21 |
Correct |
5 ms |
14928 KB |
Output is correct |
22 |
Correct |
51 ms |
19720 KB |
Output is correct |
23 |
Correct |
40 ms |
19792 KB |
Output is correct |
24 |
Correct |
70 ms |
27984 KB |
Output is correct |
25 |
Correct |
58 ms |
25824 KB |
Output is correct |
26 |
Correct |
66 ms |
27832 KB |
Output is correct |
27 |
Correct |
54 ms |
25672 KB |
Output is correct |
28 |
Correct |
57 ms |
25440 KB |
Output is correct |
29 |
Correct |
63 ms |
26696 KB |
Output is correct |
30 |
Correct |
68 ms |
27212 KB |
Output is correct |
31 |
Correct |
61 ms |
25808 KB |
Output is correct |
32 |
Correct |
90 ms |
25836 KB |
Output is correct |
33 |
Correct |
100 ms |
26080 KB |
Output is correct |
34 |
Correct |
61 ms |
25928 KB |
Output is correct |
35 |
Correct |
69 ms |
25988 KB |
Output is correct |
36 |
Correct |
75 ms |
25736 KB |
Output is correct |
37 |
Correct |
67 ms |
27268 KB |
Output is correct |
38 |
Correct |
68 ms |
24196 KB |
Output is correct |
39 |
Correct |
64 ms |
22048 KB |
Output is correct |
40 |
Correct |
77 ms |
27168 KB |
Output is correct |
41 |
Correct |
68 ms |
24100 KB |
Output is correct |
42 |
Correct |
74 ms |
20512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14672 KB |
Output is correct |
2 |
Correct |
2 ms |
14672 KB |
Output is correct |
3 |
Correct |
2 ms |
14672 KB |
Output is correct |
4 |
Correct |
2 ms |
14672 KB |
Output is correct |
5 |
Correct |
3 ms |
14928 KB |
Output is correct |
6 |
Correct |
2 ms |
14672 KB |
Output is correct |
7 |
Correct |
3 ms |
14672 KB |
Output is correct |
8 |
Correct |
3 ms |
14672 KB |
Output is correct |
9 |
Correct |
2 ms |
14812 KB |
Output is correct |
10 |
Correct |
2 ms |
14672 KB |
Output is correct |
11 |
Correct |
2 ms |
14672 KB |
Output is correct |
12 |
Correct |
2 ms |
14672 KB |
Output is correct |
13 |
Correct |
4 ms |
14928 KB |
Output is correct |
14 |
Correct |
3 ms |
14928 KB |
Output is correct |
15 |
Correct |
3 ms |
14928 KB |
Output is correct |
16 |
Correct |
4 ms |
15104 KB |
Output is correct |
17 |
Correct |
3 ms |
14928 KB |
Output is correct |
18 |
Correct |
3 ms |
10832 KB |
Output is correct |
19 |
Correct |
3 ms |
12880 KB |
Output is correct |
20 |
Correct |
4 ms |
14944 KB |
Output is correct |
21 |
Correct |
5 ms |
14928 KB |
Output is correct |
22 |
Correct |
98 ms |
18284 KB |
Output is correct |
23 |
Correct |
92 ms |
21856 KB |
Output is correct |
24 |
Correct |
114 ms |
22876 KB |
Output is correct |
25 |
Correct |
210 ms |
25360 KB |
Output is correct |
26 |
Correct |
95 ms |
22776 KB |
Output is correct |
27 |
Correct |
203 ms |
32216 KB |
Output is correct |
28 |
Correct |
223 ms |
32272 KB |
Output is correct |
29 |
Correct |
81 ms |
23236 KB |
Output is correct |
30 |
Correct |
79 ms |
18720 KB |
Output is correct |
31 |
Correct |
81 ms |
19412 KB |
Output is correct |
32 |
Correct |
190 ms |
24864 KB |
Output is correct |
33 |
Correct |
80 ms |
21604 KB |
Output is correct |
34 |
Correct |
2 ms |
12624 KB |
Output is correct |
35 |
Correct |
2 ms |
12624 KB |
Output is correct |
36 |
Correct |
1 ms |
6480 KB |
Output is correct |
37 |
Correct |
2 ms |
6480 KB |
Output is correct |
38 |
Correct |
5 ms |
12880 KB |
Output is correct |
39 |
Correct |
4 ms |
14928 KB |
Output is correct |
40 |
Correct |
4 ms |
14928 KB |
Output is correct |
41 |
Correct |
91 ms |
18652 KB |
Output is correct |
42 |
Correct |
84 ms |
19384 KB |
Output is correct |
43 |
Correct |
203 ms |
24612 KB |
Output is correct |
44 |
Correct |
74 ms |
21528 KB |
Output is correct |
45 |
Correct |
58 ms |
25988 KB |
Output is correct |
46 |
Correct |
60 ms |
27748 KB |
Output is correct |
47 |
Correct |
66 ms |
25764 KB |
Output is correct |
48 |
Correct |
64 ms |
25752 KB |
Output is correct |
49 |
Correct |
65 ms |
24020 KB |
Output is correct |
50 |
Correct |
64 ms |
25888 KB |
Output is correct |
51 |
Correct |
392 ms |
63116 KB |
Output is correct |
52 |
Correct |
452 ms |
71724 KB |
Output is correct |
53 |
Correct |
461 ms |
70984 KB |
Output is correct |
54 |
Correct |
469 ms |
71308 KB |
Output is correct |
55 |
Correct |
397 ms |
68452 KB |
Output is correct |
56 |
Correct |
51 ms |
19720 KB |
Output is correct |
57 |
Correct |
40 ms |
19792 KB |
Output is correct |
58 |
Correct |
70 ms |
27984 KB |
Output is correct |
59 |
Correct |
58 ms |
25824 KB |
Output is correct |
60 |
Correct |
66 ms |
27832 KB |
Output is correct |
61 |
Correct |
54 ms |
25672 KB |
Output is correct |
62 |
Correct |
57 ms |
25440 KB |
Output is correct |
63 |
Correct |
63 ms |
26696 KB |
Output is correct |
64 |
Correct |
68 ms |
27212 KB |
Output is correct |
65 |
Correct |
61 ms |
25808 KB |
Output is correct |
66 |
Correct |
90 ms |
25836 KB |
Output is correct |
67 |
Correct |
100 ms |
26080 KB |
Output is correct |
68 |
Correct |
61 ms |
25928 KB |
Output is correct |
69 |
Correct |
69 ms |
25988 KB |
Output is correct |
70 |
Correct |
75 ms |
25736 KB |
Output is correct |
71 |
Correct |
67 ms |
27268 KB |
Output is correct |
72 |
Correct |
68 ms |
24196 KB |
Output is correct |
73 |
Correct |
64 ms |
22048 KB |
Output is correct |
74 |
Correct |
77 ms |
27168 KB |
Output is correct |
75 |
Correct |
68 ms |
24100 KB |
Output is correct |
76 |
Correct |
74 ms |
20512 KB |
Output is correct |
77 |
Correct |
477 ms |
69984 KB |
Output is correct |
78 |
Correct |
569 ms |
69980 KB |
Output is correct |
79 |
Correct |
487 ms |
69304 KB |
Output is correct |
80 |
Correct |
468 ms |
69728 KB |
Output is correct |
81 |
Correct |
397 ms |
69076 KB |
Output is correct |
82 |
Correct |
417 ms |
68476 KB |
Output is correct |
83 |
Correct |
463 ms |
63068 KB |
Output is correct |
84 |
Correct |
437 ms |
63068 KB |
Output is correct |
85 |
Correct |
564 ms |
70064 KB |
Output is correct |
86 |
Correct |
441 ms |
62888 KB |
Output is correct |
87 |
Correct |
434 ms |
70420 KB |
Output is correct |
88 |
Correct |
449 ms |
61496 KB |
Output is correct |