#include <stdio.h>
#include <stdlib.h>
#define M 1000000
#define MD 0x7fffffff
#define X 123456789
long long min(long long a, long long b) { return a < b ? a : b; }
long long *ek[M]; int *ev[M], eo[M];
void init() {
int h;
for (h = 0; h < M; h++) {
ek[h] = (long long *) malloc(2 * sizeof *ek[h]);
ev[h] = (int *) malloc(2 * sizeof *ev[h]);
}
}
int hash(long long k) {
int k1 = k / MD, k2 = k % MD;
return ((long long) k1 * X + k2) % MD * X % MD % M;
}
void put(long long k, int v) {
int h = hash(k), o = eo[h]++;
if (o >= 2 && (o & o - 1) == 0) {
ek[h] = (long long *) realloc(ek[h], o * 2 * sizeof *ek[h]);
ev[h] = (int *) realloc(ev[h], o * 2 * sizeof *ev[h]);
}
ek[h][o] = k, ev[h][o] = v;
}
int get(long long k) {
int h = hash(k), o;
for (o = eo[h]; o--; )
if (ek[h][o] == k)
return ev[h][o];
return -1;
}
int c, cnt;
int solve(long long x1, long long y1, long long x2, long long y2) {
long long y, z;
int w;
if (x1 + y1 * c <= 0)
return 0;
if (x2 + y2 * c <= 0)
return 1;
if (x1 <= 0) {
if (x2 > 0) {
if (x2 >= c)
return 0;
if (y2 > 0) {
if (x2 - x1 >= c)
return 0;
return !solve(x2, y2, x1 + c, y1 - 1);
}
y = -x1 / (c - x2) + 1;
return y <= y1 && solve(x1 + y * (c - x2), y1 - y, x2, y2);
} else {
y = min(-x1 / c + 1, -x2 / c + 1);
return solve(x1 + y * c, y1 - y, x2 + y * c, y2 - y);
}
}
if (x1 >= x2 && (x1 >= c || y1 > 0))
return 1;
if (x2 >= c)
return !solve(x2 - x1, y2, x1, y1);
z = x1 >= 0 && x1 <= c && y1 >= 0 && y1 <= c && x2 >= 0 && x2 <= c && y2 >= 0 && y2 <= c ? (((long long) x1 * (c + 1) + y1) * (c + 1) + x2) * (c + 1) + y2 : -1;
if (z != -1 && (w = get(z)) != -1)
return w;
if (cnt < M)
cnt++;
else
z = -1;
if (!solve(x2 - x1, y2, x1, y1)) {
if (z != -1)
put(z, 1);
return 1;
}
w = x2 < c && y1 > 0 && solve(x1 + (c - x2) * y1, 0, x2, y2);
if (z != -1)
put(z, w);
return w;
}
int main() {
int t;
init();
scanf("%d%d", &c, &t);
while (t--) {
long long x1, y1, x2, y2;
scanf("%lld%lld%lld%lld", &x1, &y2, &x2, &y1), x1 -= y1 * c, x2 -= y2 * c;
printf(solve(x1, y1, x2, y2) ? "YES\n" : "NO\n");
}
return 0;
}
Compilation message
gradingserver.c: In function 'put':
gradingserver.c:30:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
30 | if (o >= 2 && (o & o - 1) == 0) {
| ~~^~~
gradingserver.c: In function 'main':
gradingserver.c:98:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
98 | scanf("%d%d", &c, &t);
| ^~~~~~~~~~~~~~~~~~~~~
gradingserver.c:102:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
102 | scanf("%lld%lld%lld%lld", &x1, &y2, &x2, &y1), x1 -= y1 * c, x2 -= y2 * c;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
79240 KB |
Output is correct |
2 |
Correct |
46 ms |
79240 KB |
Output is correct |
3 |
Correct |
41 ms |
79216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
79184 KB |
Output is correct |
2 |
Correct |
80 ms |
80204 KB |
Output is correct |
3 |
Correct |
83 ms |
82512 KB |
Output is correct |
4 |
Correct |
99 ms |
83208 KB |
Output is correct |
5 |
Correct |
83 ms |
83364 KB |
Output is correct |
6 |
Incorrect |
87 ms |
83284 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
79184 KB |
Output is correct |
2 |
Correct |
80 ms |
80204 KB |
Output is correct |
3 |
Correct |
83 ms |
82512 KB |
Output is correct |
4 |
Correct |
99 ms |
83208 KB |
Output is correct |
5 |
Correct |
83 ms |
83364 KB |
Output is correct |
6 |
Incorrect |
87 ms |
83284 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
80252 KB |
Output is correct |
2 |
Correct |
106 ms |
80264 KB |
Output is correct |
3 |
Correct |
110 ms |
80116 KB |
Output is correct |
4 |
Correct |
39 ms |
79196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
79184 KB |
Output is correct |
2 |
Correct |
80 ms |
80204 KB |
Output is correct |
3 |
Correct |
83 ms |
82512 KB |
Output is correct |
4 |
Correct |
99 ms |
83208 KB |
Output is correct |
5 |
Correct |
83 ms |
83364 KB |
Output is correct |
6 |
Incorrect |
87 ms |
83284 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
79184 KB |
Output is correct |
2 |
Correct |
80 ms |
80204 KB |
Output is correct |
3 |
Correct |
83 ms |
82512 KB |
Output is correct |
4 |
Correct |
99 ms |
83208 KB |
Output is correct |
5 |
Correct |
83 ms |
83364 KB |
Output is correct |
6 |
Incorrect |
87 ms |
83284 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
79184 KB |
Output is correct |
2 |
Correct |
80 ms |
80204 KB |
Output is correct |
3 |
Correct |
83 ms |
82512 KB |
Output is correct |
4 |
Correct |
99 ms |
83208 KB |
Output is correct |
5 |
Correct |
83 ms |
83364 KB |
Output is correct |
6 |
Incorrect |
87 ms |
83284 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
79184 KB |
Output is correct |
2 |
Correct |
80 ms |
80204 KB |
Output is correct |
3 |
Correct |
83 ms |
82512 KB |
Output is correct |
4 |
Correct |
99 ms |
83208 KB |
Output is correct |
5 |
Correct |
83 ms |
83364 KB |
Output is correct |
6 |
Incorrect |
87 ms |
83284 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |