This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxn=1e5+5,M=1e9+7;
int n,q;
int cal(int x,int y){
ll w=max(abs(x),abs(y));
ll z=w*2+1,zz=z*z;
if(-w==x)
return (zz-(w-y))%M;
zz-=z;
if(-w==y)
return (zz-(x+w-1))%M;
zz-=z-1;
if(x==w)
return (zz-(y+w-1))%M;
zz-=z-1;
return (zz-(w-1-x))%M;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
while(q--){
int x,y,xx,yy;
cin>>y>>x>>yy>>xx;
ll ans=0;
if(x<=0 && xx>=0 &&y<=0 && yy>=0)ans++;
for(int i=1;i<=n;i++){
if(x<=-i && xx>=-i){
if(y<= i && yy>=-i){
ll a=cal(-i,max(-i,y)),b=cal(-i,min(yy,i));
ans+=(a+b)*(b-a+1)/2;
ans%=M;
}
}
if(y<=-i && yy>=-i){
if(x<= i && xx>=-i+1){
ll b=cal(max(-i+1,x),-i),a=cal(min(xx,i),-i);
ans+=(a+b)*(b-a+1)/2;
ans%=M;
}
}
if(x<=i && xx>=i){
if(y<= i && yy>=-i+1){
ll b=cal(i,max(-i+1,y)),a=cal(i,min(yy,i));
ans+=(a+b)*(b-a+1)/2;
ans%=M;
}
}
if(y<=i && yy>=i){
if(x<= i-1 && xx>=-i+1){
ll a=cal(max(-i+1,x),i),b=cal(min(xx,i-1),i);
ans+=(a+b)*(b-a+1)/2;
ans%=M;
}
}
}
cout<<ans<<'\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |