Pagini recente » Cod sursa (job #699306) | Cod sursa (job #921270) | Cod sursa (job #1214411) | Cod sursa (job #2514174) | Cod sursa (job #659166)
Cod sursa(job #659166)
#include <cstdio>
struct pct {long x; long y;} a[100001], st, fn, aux;
long N, K;
long i, j, t, nr;
int main() {
freopen("gropi.in","r",stdin);
freopen("gropi.out","w",stdout);
scanf("%ld %ld", &N, &K);
for (i = 1; i <= K; ++i)
scanf("%ld %ld", &a[i].x, &a[i].y);
for (i = 1; i < K; ++i)
for (j = i + 1; j <= K; ++j)
if (a[i].x > a[j].x)
aux = a[i], a[i] = a[j], a[j] = aux;
scanf("%ld", &t);
while (t) {
scanf("%ld %ld %ld %ld", &st.x, &st.y, &fn.x, &fn.y);
if (st.y > fn.y)
aux = st, st = fn, fn = aux;
nr = fn.y - st.y + 1;
for (i = 1; i <= K && a[i].y <= fn.y; ++i)
if (a[i].y > st.y)
if (a[i].x == st.x)
++nr, st.x = 3 - st.x;
if (st.x != fn.x)
++nr;
printf("%ld\n", nr);
--t;
}
return 0;
}