#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9+7;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
int N = 2*n+1;
vector<vector<int>> num(N, vector<int> (N));
int x = n, y = n, val = 1;
num[x][y] = val;
for (int i = 1; i <= n+1; i++) { //calculate grid numbers
for (int j = 0; j < i; j++) {
x++; val++;
num[x][y] = val;
}
for (int j = 0; j < i; j++) {
y++; val++;
num[x][y] = val;
}
i++;
for (int j = 0; j < i; j++) {
x--; val++;
num[x][y] = val;
}
for (int j = 0; j < i; j++) {
y--; val++;
num[x][y] = val;
}
}
while (x+1 < N) {
x++; val++;
num[x][y] = val;
}
//~ for (int i = N-1; i >= 0; i--) {
//~ for (int j = 0; j < N; j++) {
//~ cout << num[j][i] << " ";
//~ }
//~ cout << endl;
//~ }
for (int i = 0; i < q; i++) { //do queries
int x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
x1 += n; y1 += n; x2 += n; y2 += n;
int ans = 0;
for (int j = x1; j <= x2; j++) {
for (int k = y1; k <= y2; k++) {
ans += num[j][k];
ans = ans%mod;
}
}
cout << ans << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
187 ms |
31832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
137 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
187 ms |
31832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
133 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
187 ms |
31832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |