题目描述
题解
枚举外层变成s^2-a^2的形式,平方求和算即可
code
#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define sqr(x) ((((x)%100000000)*((x)%100000000))%100000000)
#define add(a,b) a=((a)+(b))%100000000
#define mod 100000000
#define ll long long
//#define file
using namespace std;
ll n,X1,Y1,X2,Y2,i,j,k,l,ans,Ans,s;
ll Js(ll n)
{
ll s1=n,s2=n+1,s3=n+n+1;
if (!(s1%2)) s1/=2; else if (!(s2%2)) s2/=2; else s3/=2;
if (!(s1%3)) s1/=3; else if (!(s2%3)) s2/=3; else s3/=3;
return ((s1%mod)*(s2%mod)%mod*(s3%mod))%mod;
}
ll js(ll x,ll y) {return (Js(y)-Js(x-1))%mod;}
int main()
{
#ifdef file
freopen("loj6676.in","r",stdin);
#endif
scanf("%lld%lld%lld%lld%lld",&n,&X1,&Y1,&X2,&Y2);
fo(i,1,(n+1)/2)
{
Ans=0;
s=(n*n-sqr(n-(i*2-1)))%mod;
if (X1<=i && i<=X2 && max(i+1,Y1)<=min(n-i,Y2)) add(Ans,(sqr(s)*(min(n-i,Y2)-max(i+1,Y1)+1))%mod-js((n-i-min(n-i,Y2))+(n-(i-1)*2),(n-i-max(i+1,Y1))+(n-(i-1)*2)));
if (Y1<=i && i<=Y2 && max(i+1,X1)<=min(n-i,X2)) add(Ans,(sqr(s)*(min(n-i,X2)-max(i+1,X1)+1))%mod-js((n-i-min(n-i,X2))+(n-(i-1)*2),(n-i-max(i+1,X1))+(n-(i-1)*2)));
if (X1<=n-i+1 && n-i+1<=X2 && max(i+1,Y1)<=min(n-i,Y2)) add(Ans,(sqr(s)*(min(n-i,Y2)-max(i+1,Y1)+1))%mod-js((n-i-min(n-i,Y2))+1,(n-i-max(i+1,Y1))+1));
if (Y1<=n-i+1 && n-i+1<=Y2 && max(i+1,X1)<=min(n-i,X2)) add(Ans,(sqr(s)*(min(n-i,X2)-max(i+1,X1)+1))%mod-js((n-i-min(n-i,X2))+1,(n-i-max(i+1,X1))+1));
if (X1<=i && i<=X2 && Y1<=i && i<=Y2) add(Ans,sqr(s-2*(n-i*2+1)));
if (X1<=i && i<=X2 && Y1<=n-i+1 && n-i+1<=Y2) add(Ans,sqr(s)-sqr(n-i*2+1));
if (X1<=n-i+1 && n-i+1<=X2 && Y1<=i && i<=Y2) add(Ans,sqr(s)-sqr(n-i*2+1));
if (X1<=n-i+1 && n-i+1<=X2 && Y1<=n-i+1 && n-i+1<=Y2) add(Ans,sqr(s));
add(ans,Ans*i);
}
printf("%lld
",(ans+mod)%mod);
fclose(stdin);
fclose(stdout);
return 0;
}