HDOJ 4533 威威猫系列故事——晒被子

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值