Untitled
raw download clone
C
views 8
,
size 973 b
#include<stdio.h>

long int pre[200000]= {0};//1 20000 35000 50000

int main(void)
{
    int T,a,b,c,d;
    long long ans=0;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d%d",&a,&b,&c,&d);
        int bound=b+c+d;
        for(int i=a; i<=b; i++)
        {
            pre[i+b]++;
            pre[i+c+1]--;
        }
        for(int j=a+b; j<=bound; j++) //算(邊長1+邊長2)==i時有幾組
        {
            pre[j]+=pre[j-1];

        }
        for(int i=a+b; i<=bound; i++) //算(邊長1+邊長2)<=i時有幾組
        {
            pre[i]+=pre[i-1];
            //printf("pre[%d]=%d\n",i,pre[i]);
        }

        for(int i=c; i<=d; i++)
        {
            ans+=(pre[bound]-pre[i]);
            //if(ans<0)printf("%ld-%ld\n",pre[bound],pre[i]);
        }
        printf("%lld\n",ans);
        for(int i=0; i<=bound; i++)
        {
            pre[i]=0;
        }
        ans=0;
    }
    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.