#include <stdio.h>
#define N 200000
#define L 17 /* L = floor(log2(N)) */
unsigned int Z = 12345;
int rand_() {
return (Z *= 3) >> 1;
}
int xx[N], yy[N];
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k) {
int c = xx[ii[j]] != xx[i_] ? xx[ii[j]] - xx[i_] : yy[ii[j]] - yy[i_];
if (c == 0)
j++;
else if (c < 0) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
}
sort(ii, l, i);
l = k;
}
}
int search(int *ii, int n, int x, int y) {
int lower = -1, upper = n;
while (upper - lower > 1) {
int i = (lower + upper) / 2;
if (xx[ii[i]] > x || xx[ii[i]] == x && yy[ii[i]] >= y)
upper = i;
else
lower = i;
}
return upper == n || xx[ii[upper]] > x ? -1 : ii[upper];
}
int main() {
static int ii[N], pp[L + 1][N];
int n, t, i, l;
scanf("%*d%*d%d", &n);
for (i = 0; i < n; i++) {
scanf("%d%d", &xx[i], &yy[i]);
ii[i] = i;
}
sort(ii, 0, n);
for (i = 0; i < n; i++)
pp[0][i] = search(ii, n, xx[i] + 1, yy[i]);
for (l = 0; l < L; l++)
for (i = 0; i < n; i++)
pp[l + 1][i] = pp[l][i] == -1 ? -1 : pp[l][pp[l][i]];
scanf("%d", &t);
while (t--) {
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
if (x1 > x2) {
printf("No\n");
continue;
}
if (x1 == x2) {
printf(y1 <= y2 ? "Yes\n" : "No\n");
continue;
}
if (x2 - x1 > n) {
printf("No\n");
continue;
}
i = search(ii, n, x1, y1);
if (i == -1) {
printf("No\n");
continue;
}
x1++;
for (l = L; l >= 0 && i != -1; l--)
if (x2 - x1 >= 1 << l)
x1 += 1 << l, i = pp[l][i];
printf(i != -1 && yy[i] <= y2 ? "Yes\n" : "No\n");
}
return 0;
}
Compilation message
trampoline.c: In function 'search':
trampoline.c:42:39: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
42 | if (xx[ii[i]] > x || xx[ii[i]] == x && yy[ii[i]] >= y)
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
trampoline.c: In function 'main':
trampoline.c:54:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
54 | scanf("%*d%*d%d", &n);
| ^~~~~~~~~~~~~~~~~~~~~
trampoline.c:56:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | scanf("%d%d", &xx[i], &yy[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
trampoline.c:65:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | scanf("%d", &t);
| ^~~~~~~~~~~~~~~
trampoline.c:69:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
69 | scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1108 KB |
200 token(s): yes count is 21, no count is 179 |
2 |
Correct |
5 ms |
1236 KB |
200 token(s): yes count is 70, no count is 130 |
3 |
Correct |
3 ms |
980 KB |
197 token(s): yes count is 25, no count is 172 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
119 ms |
16612 KB |
4000 token(s): yes count is 99, no count is 3901 |
2 |
Correct |
117 ms |
18548 KB |
4000 token(s): yes count is 91, no count is 3909 |
3 |
Correct |
120 ms |
18240 KB |
4000 token(s): yes count is 4000, no count is 0 |
4 |
Correct |
126 ms |
18584 KB |
4000 token(s): yes count is 1991, no count is 2009 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
234 ms |
25040 KB |
200000 token(s): yes count is 110486, no count is 89514 |
2 |
Correct |
250 ms |
29036 KB |
200000 token(s): yes count is 114664, no count is 85336 |
3 |
Correct |
252 ms |
29008 KB |
200000 token(s): yes count is 86232, no count is 113768 |
4 |
Correct |
254 ms |
29116 KB |
200000 token(s): yes count is 94603, no count is 105397 |
5 |
Correct |
258 ms |
29088 KB |
200000 token(s): yes count is 94148, no count is 105852 |
6 |
Correct |
243 ms |
28984 KB |
200000 token(s): yes count is 97163, no count is 102837 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
724 KB |
5000 token(s): yes count is 3238, no count is 1762 |
2 |
Correct |
5 ms |
1108 KB |
5000 token(s): yes count is 3837, no count is 1163 |
3 |
Correct |
4 ms |
1108 KB |
5000 token(s): yes count is 4104, no count is 896 |
4 |
Correct |
5 ms |
1108 KB |
5000 token(s): yes count is 3934, no count is 1066 |
5 |
Correct |
5 ms |
1108 KB |
5000 token(s): yes count is 3384, no count is 1616 |
6 |
Correct |
5 ms |
1068 KB |
5000 token(s): yes count is 3390, no count is 1610 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
334 ms |
25012 KB |
200000 token(s): yes count is 171404, no count is 28596 |
2 |
Correct |
309 ms |
29080 KB |
200000 token(s): yes count is 161254, no count is 38746 |
3 |
Correct |
261 ms |
29052 KB |
200000 token(s): yes count is 117455, no count is 82545 |
4 |
Correct |
318 ms |
28960 KB |
200000 token(s): yes count is 182118, no count is 17882 |
5 |
Correct |
272 ms |
29064 KB |
200000 token(s): yes count is 167565, no count is 32435 |
6 |
Correct |
269 ms |
29132 KB |
200000 token(s): yes count is 156797, no count is 43203 |
7 |
Correct |
275 ms |
29132 KB |
200000 token(s): yes count is 156797, no count is 43203 |
8 |
Correct |
266 ms |
29132 KB |
200000 token(s): yes count is 122100, no count is 77900 |
9 |
Correct |
307 ms |
29056 KB |
200000 token(s): yes count is 139670, no count is 60330 |
10 |
Correct |
309 ms |
28976 KB |
200000 token(s): yes count is 165806, no count is 34194 |
11 |
Correct |
302 ms |
28976 KB |
200000 token(s): yes count is 175646, no count is 24354 |
12 |
Correct |
231 ms |
29136 KB |
200000 token(s): yes count is 134695, no count is 65305 |
13 |
Correct |
271 ms |
29056 KB |
200000 token(s): yes count is 126733, no count is 73267 |
14 |
Correct |
283 ms |
29176 KB |
200000 token(s): yes count is 155290, no count is 44710 |
15 |
Correct |
245 ms |
29144 KB |
200000 token(s): yes count is 129674, no count is 70326 |