HDU-4419 Colourful Rectangle 矩形多面积并
题目链接: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 矩形多面积并的更多相关文章
- [HDU 4419] Colourful Rectangle (扫描线 矩形面积并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4419 题目大意:比矩形面积并多了颜色,问染成的每种颜色的面积. 矩形面积并的扫描线维护的是长度,这道题 ...
- hdu 4419 Colourful Rectangle
http://acm.hdu.edu.cn/showproblem.php?pid=4419 题意:给出3种颜色,重叠会生成新的颜色,然后有一些矩形,求出每种颜色的面积. 转化为二进制表示颜色:001 ...
- hdu 4419 Colourful Rectangle (离散化扫描线线段树)
Problem - 4419 题意不难,红绿蓝三种颜色覆盖在平面上,不同颜色的区域相交会产生新的颜色,求每一种颜色的面积大小. 比较明显,这题要从矩形面积并的方向出发.如果做过矩形面积并的题,用线段树 ...
- HDU 4419 Colourful Rectangle --离散化+线段树扫描线
题意: 有三种颜色的矩形n个,不同颜色的矩形重叠会生成不同的颜色,总共有R,G,B,RG,RB,GB,RGB 7种颜色,问7种颜色每种颜色的面积. 解法: 很容易想到线段树扫描线求矩形面积并,但是如何 ...
- HDU 4419 Colourful Rectangle(线段树+扫描线)
题目链接 主要是pushup的代码,其他和区间更新+扫描线差不多. 那个区间如果要再刷一层x,那么sum[x][rt] = que[r+1] - que[l];但是如果原本有颜色为i,颜色将会变成i| ...
- HDU 1506 Largest Rectangle in a Histogram set+二分
Largest Rectangle in a Histogram Problem Description: A histogram is a polygon composed of a sequenc ...
- hdu 1506 Largest Rectangle in a Histogram(单调栈)
L ...
- TZOJ 2392 Bounding box(正n边形三点求最小矩形覆盖面积)
描述 The Archeologists of the Current Millenium (ACM) now and then discover ancient artifacts located ...
- HDU 1506 Largest Rectangle in a Histogram(DP)
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
随机推荐
- Python用format格式化字符串
format是是python2.6新增的一个格式化字符串的方法,相对于老版的%格式方法,它有很多优点. 1.不需要理会数据类型的问题,在%方法中%s只能替代字符串类型 2.单个参数可以多次输出,参数顺 ...
- 2016041601 - linux上安装maven
在linux系统中安装maven,个人目前使用ubuntu15.1系统. 要想使用maven,前提条件必须配置好java. 1.检查java信息. 命令:echo $JAVA_HOME 和java - ...
- Qt 5 常见错误汇总
1.没加 QT+=sql,需要再.pro文件中加上 2.无故崩溃,这个有多种原因,多为指针问题,例如,指针内存泄露,指针未开辟空间直接使用,UI还未建立就使用UI里面的东西..等等 3.Sql问题,有 ...
- 深度(Depth)概念
强化对深度的理解 在老版本的NGUI中,UI的显示层次关系是依靠z轴进行的.在新版本的NGUI中,所有UI的z轴都被统一,然后用深度来决定和管理显示的层次关系.关于深度,要记住一下关键点: 1.每一个 ...
- C++学习笔记——一只P转C的OIer的学习历程
2015-11-29 第一天接触c++(也不能这不说,看c++的程序也看了不少).重新找回了当时学pascal的感觉,从Hello World 开始写起,感觉自己的智商降低了,期间犯了各种弱智到不能再 ...
- js构造函数传参
1.直接传参并用this关键字初始化属性 function Person(name,age,learn){ this.name = name; this.age = age; this.learn = ...
- stdout 编码 vim 删除左边,右边
sys.stdout = codecs.getwriter('utf8')(sys.stdout) vimdic['kkkk'] = qqqqqdic['bbbb'] = aaaaaadic['kkk ...
- 浏览我的php网页时,出现的都是网页的代码
添加php模块 ,在apache/conf/httpd.conf,如果是windows下的话,添加如下代码,具体路径你根据具体情况设置#BEGIN PHP INSTALLER EDITS - REMO ...
- WP8教程
http://www.maiziedu.com/courses-list?technology_category=6
- JDBC MySQL字段类型为datetime的数据取出(util.Date)
使用ResultSet的getTimestamp方法获取java.util.Date型数据 java.util.Date time = rs.getTimestamp("time" ...