Untitled
raw download clone
TEXT
views 15
,
size 576 b
#include<stdio.h>
int p[100005];
int main()
{
	int n;
	scanf("%d", &n);
	int a, b, c, d;
	long long int ans;
	while (n--) {
		for (int i = 0; i <= 100005; i++) p[i] = 0;
		scanf("%d %d %d %d", &a, &b, &c, &d);
		ans = 0;
		for (int i = a; i <= b; i++) {
			p[i + b] = 1;
			p[i + c + 1] = -1;
		}
		for (int i = a + b; i <= c+d+1; i++) {
			p[i] = p[i - 1] + p[i];
		}
		for (int i = a + b-1; i <=c+d+1; i++) {
			p[i] = p[i - 1] + p[i];
		}
		for (int i = c; i <= d; i++) {
			ans += (p[c+d+1] - p[i]);
		}
		printf("%lld\n", ans);
	}
	return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.