#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> grid;
typedef long long int ll;
ll MOD = 1e9 + 7;
ll at_poll(ll x, ll y) {
y *= -1;
if (x == 0 && y == 0)
return 1;
ll loc = max(abs(x), abs(y));
ll slen = (2 * loc - 1);
ll val = slen * slen;
if (y == loc)
val += 6 * loc + loc + x;
else if (x == -loc)
val += 4 * loc + loc + y;
else if (y == -loc)
val += 2 * loc + loc - x;
else if (x == loc)
val += loc - y;
return val;
}
int main() {
int n, q;
cin >> n >> q;
for (int i = 0; i < q; i++) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
ll ans = 0;
for (int x = x1; x <= x2; x++)
for (int y = y1; y <= y2; y++)
ans = (ans + at_poll(x, y)) % MOD;
cout << ans << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |