Untitled
raw download clone
C
views 17
,
size 922 b
#include <stdio.h>
#include <stdlib.h>
long pre1[500001], pre2[500001], state[500001];

int main(void)
{
    int n, a, b, c, d;
    long ans;
    scanf("%d", &n);
    while (n--)
    {
        pre1[0] = 0;
        pre2[0] = 0;
        ans = 0;
        scanf("%d %d %d %d", &a, &b, &c, &d);
        for (int i = a; i <= b; i++)
        {
            state[i+b]++;
            state[i+c+1]--;
        }
        for (int i = 1; i <= b+c; i++)
        {
            pre1[i] = pre1[i - 1] + state[i];
        }
        for (int i = 1; i <= c+d; i++)
        {
            pre2[i] = pre2[i-1]+pre1[i];
        }
        for (int j = c; j <= d; j++)
        {
            ans += (pre2[c+d]-pre2[j]);
        }
        printf("%ld\n", ans);

        for (int i = 0; i <= 500001; i++)
        {
            state[i] = 0;
            pre2[i] = 0;
            pre1[i] = 0;
        }
    }
}
close fullscreen
Login or Register to edit or fork this paste. It's free.