#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <set>
#define LL long long
#define FOR(i,x,y) for(int i=x;i<=y;i++)
#define rFOR(i,x,y) for(int i=x;i>=y;i--)
#define CLR(x,k) memset(x,k,sizeof(x))
#define lson l , m , rt<<1
#define rson m + 1 , r , rt<<1|1
using namespace std;
const int MAXN = 200005;
struct BIT
{
LL C[MAXN];
int lowbit(int x) { return x & -x; }
void clear() { memset(C , 0 , sizeof(C)); }
void add(int l , int r , LL d)
{
for(int i = l ; i < MAXN ; i += lowbit(i)) C[i] += d;
for(int i = r + 1; i < MAXN ; i += lowbit(i)) C[i] -= d;
}
LL sum(int x)
{
LL res = 0;
for(int i = x ; i > 0 ; i -= lowbit(i)) res += C[i];
return res;
}
}A , B , C;
void update(int l , int r , LL a , LL b , LL c)
{
A.add(l , r , a);
B.add(l , r , b);
C.add(l ,r , c);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
A.clear() ; B.clear() ; C.clear();
int N , M;
scanf("%d",&N);
LL x1 , y1 , x2 , y2;
while(N--)
{
scanf("%I64d%I64d%I64d%I64d",&x1,&y1,&x2,&y2);
if(max(x1 , y1) < min(x2 , y2))
update(max(x1 , y1) , min(x2 , y2) , 1 , - x1 - y1 , x1 * y1);
if(x2 < y2) update(max(x2 , y1) + 1 , y2 , 0 , x2 - x1 , y1 * (x1 - x2));
if(x2 > y2) update(max(y2 , x1) + 1 , x2 , 0 , y2 - y1 , x1 * (y1 - y2));
update(max(x2 , y2) + 1 , MAXN , 0 , 0 , (y2 - y1) * (x2 - x1));
}
scanf("%d",&M);
while(M--)
{
LL t;
scanf("%I64d",&t);
LL ans = 0;
ans += A.sum(t) * t * t;
ans += B.sum(t) * t;
ans += C.sum(t);
printf("%I64d\n",ans);
}
}
return 0;
}
HDOJ 4533 威威猫系列故事——晒被子
最新推荐文章于 2020-03-16 22:55:33 发布