// That's what she said !
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int maxn = 2e3 + 9 , modn = 1e9 + 7;
int n, ps[maxn][maxn], a[maxn][maxn], m, q, w, e, r;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
a[n+1][n+1] = 1;
int i = n+1 , j = n+1, k = 1, val = 2, x, y;
n = 2 * n + 1;
while(val <= n * n){
if(k % 2){
j++;
x = j + k;
for(j; j < x; j++){
a[i][j] = val;
val++;
}
j--, i--;
y = i - k;
for(i; i > y; i--){
a[i][j] = val;
val++;
}
i++;
}
else{
j--;
x = j - k;
for(j; j > x; j--){
a[i][j] = val;
val++;
}
j++, i++;
y = i + k;
for(i; i < y; i++){
a[i][j] = val;
val++;
}
i--;
}
k++;
}
for(int i = n; i > 0; i--)
for(int j = 1; j <= n; j++)
ps[n-i+1][j] = ps[n-i][j] + ps[n-i+1][j-1] - ps[n-i][j-1] + a[i][j];
cin >> m;
while(m --){
cin >> q >> w >> e >> r;
q += n/2+1, w += n/2+1, e += n/2+1, r += n/2+1;
cout << ps[r][e] - ps[r][q-1] - ps[w-1][e] + ps[w-1][q-1] << endl;
}
return 0;
}
Compilation message
spiral.cpp: In function 'int32_t main()':
spiral.cpp:23:17: warning: statement has no effect [-Wunused-value]
23 | for(j; j < x; j++){
| ^
spiral.cpp:29:17: warning: statement has no effect [-Wunused-value]
29 | for(i; i > y; i--){
| ^
spiral.cpp:38:17: warning: statement has no effect [-Wunused-value]
38 | for(j; j > x; j--){
| ^
spiral.cpp:44:17: warning: statement has no effect [-Wunused-value]
44 | for(i; i < y; i++){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
79 ms |
63116 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
492 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
79 ms |
63116 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
360 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
79 ms |
63116 KB |
Output isn't correct |