#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define debug(x) cerr<<#x<<" :"<<x<<"\n"
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define FAST ios_base::sync_with_stdio(false), cin.tie(), cout.tie();
#define int long long
typedef long long ll;
typedef long double ld;
const int maxn = 5e5 + 7;
const int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const int mlog = 20;
const int SQ = 400;
int GET(int x,int y)
{
int mx = max(abs(x), abs(y));
int res = ((2*mx - 1) * (2*mx - 1))%mod;
if(y == mx) res += (mx - x + mx*2);
else if(x == -mx) res += (mx - y + mx*4);
else if(y == -mx) res += (x + mx + mx*6);
else if(x == mx) res += (y + mx);
res %= mod;
return res;
}
int32_t main()
{
FAST;
int n, q;
cin >> n >> q;
while(q--)
{
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
int ans = 0;
for(int x = x1;x <= x2; x++) for(int y = y1; y <= y2; y++) ans = (ans + GET(x, y))%mod;
cout << ans << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
413 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
413 ms |
364 KB |
Output is correct |
2 |
Execution timed out |
1577 ms |
364 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1565 ms |
364 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
413 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Execution timed out |
1577 ms |
364 KB |
Time limit exceeded |