#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1000 * 1000 * 1000;
const ll LINF = (ll)INF * INF;
#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define msub(a, b) ((mod + ((ll)(a) - (b)) % mod) % mod)
#define mdiv(a, b) ((ll)(a) * poww((b), mod - 2) % mod)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define endl '\n'
int n, q;
ll get(int x, int y)
{
ll d = max(abs(x), abs(y)) + 1;
ll ur = 4 * d * d - 10 * d + 7;
ll off = 0;
d--;
if (y == d)
off = d - x;
else if (y == -d)
{
off = x + 5 * d;
}
else if (x == d)
{
off = y - d;
}
else if (x == -d)
{
off = 3 * d - y;
}
return ur + off;
}
ll getsum(int x, int y)
{
ll d = max(x, y);
ll res = 0;
FOR(i, 0, d)
{
ll fr = (i > x ? get(x, i) : get(i, 0));
ll sc = (i > y ? get(i, y) : get(0, i));
res = (res + (fr + sc) * (sc - fr + 1) / 2) % mod;
}
return res;
}
int32_t main(void)
{
fast_io;
cin >> n >> q;
while (q--)
{
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 == 1 && y1 == 1)
{
cout << getsum(x2, y2) << endl;
continue;
}
ll ans = 0;
FOR(i, x1, x2 + 1)
{
FOR(j, y1, y2 + 1)
{
ans = (ans + get(i, j)) % mod;
}
}
cout << ans << endl;
dbg("");
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
252 ms |
388 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
252 ms |
388 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1552 ms |
268 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
252 ms |
388 KB |
Output isn't correct |