#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[i] = 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 |
Incorrect |
413 ms |
1092 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2073 ms |
4384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2064 ms |
6700 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
199 ms |
1092 KB |
expected YES, found NO [1st token] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2052 ms |
6668 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |