• loj#6676. EntropyIncreaser 与金字塔


    题目描述

    题解

    枚举外层变成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;
    }
    
  • 相关阅读:
    字符,字符串,字节
    111
    串口通信
    字符编码
    枚举和结构体
    参数数组
    .Net垃圾回收机制
    try{ } catch{ } finally{ }
    LVS 工作原理图文讲解
    自动化运维工具—Ansible常用模块二
  • 原文地址:https://www.cnblogs.com/gmh77/p/13232804.html
Copyright © 2020-2023  润新知