#include <iostream>
using namespace std;
typedef long long LL;
LL n, q, x1, y1, x2, y2, sum;
int main() {
cin >> n >> q;
for (int i = 1; i <= q ; i++) {
sum = 0;
cin >> x1 >> y1 >> x2 >> y2;
x1++, y1++, x2++, y2++;
// 统计对角线
if (x1 <= y1) {
if (x1 != y1) {
if (x2 - y1 >= 0) sum += min(x2, y2) - y1 + 1;
}
if (x1 == y1) {
sum += min(x2, y2) - y1 + 1;
}
} else {
if (min(x2, y2) - x1 >= 0) sum += min(x2, y2) - max(x1, y1) + 1;
}
// 统计反对角线
LL tmp = y1;
y1 = n + 1 - y2;
y2 = n + 1 - tmp;
if (x1 <= y1) {
if (x1 != y1) {
if (x2 - y1 >= 0) sum += min(x2, y2) - y1 + 1;
}
if (x1 == y1) {
sum += min(x2, y2) - y1 + 1;
}
} else {
if (min(x2, y2) - x1 >= 0) sum += min(x2, y2) - max(x1, y1) + 1;
}
// 处理中心点是否被重复计算
LL mid = n / 2 + 1;
if (n & 1 == 1 && (mid >= x1 && mid <= x2 && mid >= n + 1 - y2 && mid <= n + 1 - y1)) sum--;
cout << sum << endl;
}
return 0;
}
厉害厉害,学到了~ 比我写的简单多了