Submission #83043

# Submission time Handle Problem Language Result Execution time Memory
83043 2018-11-04T11:20:14 Z FedericoS Spiral (BOI16_spiral) C++14
12 / 100
161 ms 63096 KB
#include <iostream>
using namespace std;
typedef long long int ll;

ll md=1e9+7;
ll N,Q;
ll A[2005][2005];
ll B[2005][2005];
ll C[2005][2005];
ll K=2;
ll a,b,c,d;
ll ans;

int main(){

	cin>>N;

	if(N<=1000){
		
		A[N][N]=1;

		for(ll i=1;i<N+1;i++){
			for(ll x=N+i,y=N-i+1;y<N+i+1;y++)
				A[x][y]=K++;
			for(ll x=N+i-1,y=N+i;x>N-i-1;x--)
				A[x][y]=K++;
			for(ll x=N-i,y=N+i-1;y>N-i-1;y--)
				A[x][y]=K++;
			for(ll x=N-i+1,y=N-i;x<N+i+1;x++)
				A[x][y]=K++;
				
		}

		for(ll i=1;i<2*N+2;i++)
			for(ll 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]+10*md)%md;

		cin>>Q;
		while(Q--){
			cin>>a>>b>>c>>d;
			a+=N+1,b+=N+1,c+=N+1,d+=N+1;
			ans=(B[c][d]-B[c][b-1]-B[a-1][d]+B[a-1][b-1]+10*md)%md;
			cout<<ans<<"\n";
		}

	}
	else{
		cin>>Q;
		while(Q--){
			cin>>a>>b>>a>>b;
			if(a==0 and b==0){
				cout<<"1\n";
				continue;
			}

			c=max(abs(a),abs(b));
			a+=N,b+=N;
			ans=(2*c-1)%md;
			ans=(ans*ans+1)%md;

			if(a==N+c and b>=N-c+1 and b<N+c+1){
				cout<<(ans+b-(N-c+1)+10*md)%md<<"\n";
				continue;
			}
			else
				ans=(ans+2*c)%md;

			if(a<=N+c-1 and a>N-c-1 and b==N+c){
				cout<<(ans+(N-c+1)-a+10*md)%md<<"\n";
				continue;
			}
			else
				ans=(ans+2*c)%md;

			if(a==N-c and b<=N+c-1 and b>N-c-1){
				cout<<(ans+(N+c-1)-b+10*md)%md<<"\n";
				continue;
			}
			else
				ans=(ans+2*c)%md;

			if(a>=N-c+1 and a<N+c+1 and b==N-c){
				cout<<(ans+a-(N-c+1)+10*md)%md<<"\n";
				continue;
			}
			else
				ans=(ans+2*c)%md;

		}
	}


}
# Verdict Execution time Memory Grader output
1 Correct 161 ms 63096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 63096 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 161 ms 63096 KB Output is correct
2 Incorrect 2 ms 63096 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 63096 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 161 ms 63096 KB Output is correct
2 Incorrect 2 ms 63096 KB Output isn't correct