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 SqlAlchemy使用方法
1.初始化连接 from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker engine = create ...
- uCGUI简介
何为GUI? GUI是Graphic User Interface(图形用户界面)的缩写.最早的操作系统都是字符界面,使用者必须记忆和输入许多指令.而现在广泛使用的Windows操作系统则是适应GUI ...
- 导入NGUI插件
在Unity编辑器顶部菜单栏中的Assets菜单中选择Import Package,然后选择Custom Package(自定义资源包),弹出资源路径窗口,在其中找到NGUI资源包所在的位置,单击”打 ...
- CoreGraphics之CGContext绘图
0 CGContextRef context = UIGraphicsGetCurrentContext(); 设置上下文 1 CGContextMoveToPoint 开始画线 2 CGCon ...
- delphi xe5 android iny绿色版+最新SDK/NDK安装方法
转自: http://bbs.2ccc.com/topic.asp?topicid=438595 首先感谢iny的绿色版,因为我的精简Win7 32位安装原版镜像4.63G过程正常,但是编译出错,后来 ...
- res\menu\main.xml:6: error: No resource identifier found for attribute 'showAsAction' in package 'com.xxx.xxxx'
res\menu\main.xml:6: error: No resource identifier found for attribute 'showAsAction' in package 'co ...
- HDU4523+简单
题意很简单. 一次最多多切出一条边! 其余的就没什么好说的了 import java.util.*; import java.math.*; public class Main{ public sta ...
- mysql查看'datadir'目录
mysql查看创建的数据库的数据,包含表等存放的目录,可以输入下面指令查看: show variables like 'datadir'
- Motion on Ubuntu
Motion is a program that monitors the video signal from one or more cameras and is able to detect if ...
- easyui源码翻译1.32--DateTimeBox(日期时间输入框)
前言 扩展自$.fn.datebox.defaults,使用$.fn.datetimebox.defaults重写默认值对象.下载该插件翻译源码 和日期输入框类似,日期时间输入框允许用户选择日期和指定 ...