#include <iostream>
using namespace std;
int N,Q;
int A[2005][2005];
int B[2005][2005];
int C[2005][2005];
int K=2;
int a,b,c,d;
int ans;
int main(){
cin>>N;
A[N][N]=1;
for(int i=1;i<N+1;i++){
for(int x=N+i,y=N-i+1;y<N+i+1;y++)
A[x][y]=K++;
for(int x=N+i-1,y=N+i;x>N-i-1;x--)
A[x][y]=K++;
for(int x=N-i,y=N+i-1;y>N-i-1;y--)
A[x][y]=K++;
for(int x=N-i+1,y=N-i;x<N+i+1;x++)
A[x][y]=K++;
}
for(int i=1;i<2*N+2;i++)
for(int j=1;j<2*N+2;j++)
B[i][j]=B[i-1][j]+B[i][j-1]-B[i-1][j-1]+A[i-1][j-1];
/*
for(int i=0;i<2*N+2;i++)
for(int j=0;j<2*N+2;j++)
C[i][j]=B[j][2*N+1-i];
for(int i=0;i<2*N+2;i++){
for(int j=0;j<2*N+2;j++)
cout<<B[i][j]<<" ";
cout<<endl;
}
*/
cin>>Q;
while(Q--){
cin>>a>>b>>c>>d;
a+=N+1,b+=N+1,c+=N+1,d+=N+1;
/*cout<<a<<" "<<b<<" "<<c<<" "<<d<<" ";
cout<<C[c][d]<<" "<<C[c][b-1]<<" "<<C[a-1][d]<<" "<<C[a-1][b-1]<<endl;*/
ans=B[c][d]-B[c][b-1]-B[a-1][d]+B[a-1][b-1];
cout<<ans<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
61 ms |
31712 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
31712 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
61 ms |
31712 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
31712 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
61 ms |
31712 KB |
Output isn't correct |