// YOU ONLY GOT ONE SHOT
#include <bits/stdc++.h>
#define put(x) cerr << #x << ": " << x << '\n'
#define line() cerr << "**************\n"
//#define F first
//#define S second
//#define mul(x, y) (((x) * (y)) %mod)
//#define bit(i, j) (((i)>>(j)) &1)
//#define left(id) ((id<<1) + 1)
//#define right(id) ((id<<1) + 2)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
const int mod = 1e9 + 7;
int n, q;
ll get(int x, int y){
ll d = max(abs(x - 0), abs(y - 0)) + 1;
ll a = (4 * d * d) - (10 * d) + 7, b = 0;
d--;
if(y == d)
b = d - x;
else if(y == -d)
b = x + (5 * d);
else if(x == d)
b = y - d;
else if(x == -d)
b = (3 * d) - y;
return a + b;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> q;
while(q--){
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
ll res = 0;
for(int i=x1; i<=x2; i++)
for(int j=y1; j<=y2; j++){
res = (res + get(i, j)) %mod;
}
cout << res << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
259 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
259 ms |
492 KB |
Output is correct |
2 |
Execution timed out |
1595 ms |
364 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1595 ms |
492 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
259 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Execution timed out |
1595 ms |
364 KB |
Time limit exceeded |