题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4419

  利用二进制,R为1、G为2、B为4,然后通过异或运算可以得到其它组合颜色。建立7颗线段树,每颗线段树保存每种颜色的长度。。。

 //STATUS:C++_AC_203MS_4780KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End struct Seg{
int y,x1,x2;
int c,col;
Seg(){}
Seg(int a,int b,int c,int d,int color):y(a),x1(b),x2(c),c(d),col(color){}
bool operator < (const Seg& a)const{
return y<a.y;
}
}seg[N];
int hs[N],len[N<<][];
int cnt[N<<][];
LL ans[];
int T,n,m; void pushup(int l,int r,int rt)
{
int i,col=((cnt[rt][]?:) | (cnt[rt][]?:) | (cnt[rt][]?:));
if(col){
int ls=rt<<,rs=rt<<|;
mem(len[rt],);
len[rt][col]=hs[r+]-hs[l];
i=;
for(i=;i<=;i++){
if(col==(col|i))continue;
int t=len[ls][i]+len[rs][i];
len[rt][col|i]+=t;
len[rt][col]-=t;
}
}
else if(l==r)mem(len[rt],);
else {
int ls=rt<<,rs=rt<<|;
for(i=;i<=;i++){
len[rt][i]=len[ls][i]+len[rs][i];
}
}
} void update(int a,int b,int c,int col,int l,int r,int rt)
{
if(a<=l && r<=b){
cnt[rt][col]+=c;
pushup(l,r,rt);
return;
}
int mid=(l+r)>>;
if(a<=mid)update(a,b,c,col,lson);
if(b>mid)update(a,b,c,col,rson);
pushup(l,r,rt);
} int binary(int l,int r,int tar)
{
int mid;
while(l<r){
mid=(l+r)>>;
if(hs[mid]==tar)return mid;
else if(hs[mid]>tar)r=mid;
else l=mid+;
}
return -;
} int main()
{
// freopen("in.txt","r",stdin);
int key[];
key['R']=,key['G']=,key['B']=;
int i,j,k,l,r,ca=,a,b,c,d;
char s[];
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
m=;
for(i=;i<n;i++){
scanf("%s%d%d%d%d",s,&a,&b,&c,&d);
hs[m]=a;
seg[m++]=Seg(b,a,c,,key[s[]]);
hs[m]=c;
seg[m++]=Seg(d,a,c,-,key[s[]]);
}
sort(hs,hs+m);
sort(seg,seg+m);
for(i=,k=;i<m;i++)
if(hs[i]!=hs[k])hs[++k]=hs[i];
mem(len,);mem(cnt,);mem(ans,);
for(i=;i<m-;i++){
l=binary(,k+,seg[i].x1);
r=binary(,k+,seg[i].x2)-;
if(l<=r)update(l,r,seg[i].c,seg[i].col,,k,);
for(j=;j<=;j++){
ans[j]+=(LL)len[][j]*(LL)(seg[i+].y-seg[i].y);
}
} printf("Case %d:\n%I64d\n%I64d\n%I64d\n%I64d\n%I64d\n%I64d\n%I64d\n",
ca++,ans[],ans[],ans[],ans[],ans[],ans[],ans[]);
}
return ;
}

HDU-4419 Colourful Rectangle 矩形多面积并的更多相关文章

  1. [HDU 4419] Colourful Rectangle (扫描线 矩形面积并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4419 题目大意:比矩形面积并多了颜色,问染成的每种颜色的面积. 矩形面积并的扫描线维护的是长度,这道题 ...

  2. hdu 4419 Colourful Rectangle

    http://acm.hdu.edu.cn/showproblem.php?pid=4419 题意:给出3种颜色,重叠会生成新的颜色,然后有一些矩形,求出每种颜色的面积. 转化为二进制表示颜色:001 ...

  3. hdu 4419 Colourful Rectangle (离散化扫描线线段树)

    Problem - 4419 题意不难,红绿蓝三种颜色覆盖在平面上,不同颜色的区域相交会产生新的颜色,求每一种颜色的面积大小. 比较明显,这题要从矩形面积并的方向出发.如果做过矩形面积并的题,用线段树 ...

  4. HDU 4419 Colourful Rectangle --离散化+线段树扫描线

    题意: 有三种颜色的矩形n个,不同颜色的矩形重叠会生成不同的颜色,总共有R,G,B,RG,RB,GB,RGB 7种颜色,问7种颜色每种颜色的面积. 解法: 很容易想到线段树扫描线求矩形面积并,但是如何 ...

  5. HDU 4419 Colourful Rectangle(线段树+扫描线)

    题目链接 主要是pushup的代码,其他和区间更新+扫描线差不多. 那个区间如果要再刷一层x,那么sum[x][rt] = que[r+1] - que[l];但是如果原本有颜色为i,颜色将会变成i| ...

  6. HDU 1506 Largest Rectangle in a Histogram set+二分

    Largest Rectangle in a Histogram Problem Description: A histogram is a polygon composed of a sequenc ...

  7. hdu 1506 Largest Rectangle in a Histogram(单调栈)

                                                                                                       L ...

  8. TZOJ 2392 Bounding box(正n边形三点求最小矩形覆盖面积)

    描述 The Archeologists of the Current Millenium (ACM) now and then discover ancient artifacts located ...

  9. HDU 1506 Largest Rectangle in a Histogram(DP)

    Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

随机推荐

  1. 1.0 基础、标示符、常量、数据类型(enum 枚举,struct 结构体)、操作符、循环、数组

    一.程序 现实生活中,程序是指完成某些事务的一种既定方法和过程,可以把程序看成是一系列动作执行过程的描述. 在计算机世界,程序是指令,即为了让计算机执行某些操作或解决某个问题而编写的一系列有序指令的集 ...

  2. 开发设计模式(八)抽象工厂模式(Abstract Factory Pattern)

    抽象工厂模式主要有以下角色: 抽象工厂角色:担任这个角色的是工厂方法模式的核心,它是与应用系统的商业逻辑无关的.通常使用接口或抽象类实现.    具体工厂角色:这个角色直接在客户端的调用下创建产品的实 ...

  3. Python标准库与第三方库详解(转载)

    转载地址: http://www.codeweblog.com/python%e6%a0%87%e5%87%86%e5%ba%93%e4%b8%8e%e7%ac%ac%e4%b8%89%e6%96%b ...

  4. 使用ssh公钥实现免密码登录

    使用ssh公钥实现免密码登录 ssh 无密码登录要使用公钥与私钥.linux下可以用用ssh-keygen生成公钥/私钥对,下面我以CentOS为例. 有机器A(10.207.160.34),B(10 ...

  5. PYTHON多进程编码结束之进程池POOL

    结束昨晚开始的测试. 最后一个POOL. A,使用POOL的返回结果 #coding: utf-8 import multiprocessing import time def func(msg): ...

  6. OpenStack项目列表

    这个也是必须要熟悉的哟. ~~~~~~~~~~ OpenStack是一个美国国家航空航天局和Rackspace合作研发的,以Apache许可证授权,并且是一个自由软件和开放源代码项目.OpenStac ...

  7. UVA 11090 Going in Cycle!!

    要求给定的图的中平均权值最小的环,注意处理自环的情况就能过了. 按照w1+w2+w3+….wn < n*ave的不等式,也就是(w1-ave) + (w2-ave) +…..(wn-ave) & ...

  8. ZOJ - 2615 Cells

    注意数组别开太小了,代码照着训练经典打的: #include <iostream> #include <sstream> #include <cstdio> #in ...

  9. asp.net DropDownList无刷新ajax二级联动实现详细过程

    只适合新手制作DropDownList无刷新ajax二级联动效果: 数据库实现,添加两表如图:表1,pingpai,表2,type,具体数据库实现看自己的理解: //页面主要代码: <asp:S ...

  10. 公司估值(贴现现金流量法DCF)

    创业公司总会遇到并购或者入股等情况,CEO需要了解一些公司估值的方法,本文主要介绍贴现现金流量估值方法,供大家参考: 中国资产评估协会要求:在对企业价值进行评估时,应分析收益法.市场法和资产基础法三种 ...