题目链接

主要是pushup的代码,其他和区间更新+扫描线差不多。

那个区间如果要再刷一层x,那么sum[x][rt] = que[r+1] - que[l];但是如果原本有颜色为i,颜色将会变成i|x,sum[x][rt] 要减去以前的i颜色的部分。sum[i|x][rt]要加上那部分。

这个题还可以用容斥,容斥的话,多次求面积并就可以了,代码直接是模版,对扫描线,还是不熟啊。

 #include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
#define LL __int64
#define maxn 20100
#define lson l , m, rt<<1
#define rson m+1, r,rt<<1|1
int que[*maxn];
int sum[][*maxn];
int cnt[*maxn][];
LL ans[];
struct node
{
int lx,rx,y;
int s;
node() {}
node (int a,int b,int c,int d):lx(a),rx(b),y(c),s(d) {}
bool operator < (const node &S)const
{
return y < S.y;
}
} mat[*maxn];
int bin(int x,int n)
{
int str,end,mid;
str = ;
end = n;
while(str <= end)
{
mid = (str + end)/;
if(que[mid] == x)
return mid;
else if(que[mid] > x)
end = mid - ;
else
str = mid + ;
}
return mid;
}
void pushup(int rt,int l,int r)
{
int i,x,t;
x = ;
for(i = ;i <= ;i ++)
{
if(cnt[rt][i] > )
x |= (<<(i-));
}
if(x)
{
for(i = ;i < ;i ++)
sum[i][rt] = ;
sum[x][rt] = que[r+] - que[l];
for(i = ; i < ; i ++)//注意这里
{
if(x != (i|x))
{
t = sum[i][rt<<] + sum[i][rt<<|];
sum[x|i][rt] += t;
sum[x][rt] -= t;//减去原本的其他颜色
}
}
}
else if(l == r)
{
for(i = ; i < ; i ++)
sum[i][rt] = ;
}
else
{
for(i = ; i < ; i ++)
sum[i][rt] = sum[i][rt<<] + sum[i][rt<<|];
}
}
void update(int L,int R,int c,int l,int r,int rt)
{
int m;
if(l >= L&&r <= R)
{
c > ? cnt[rt][c] ++:cnt[rt][-c] --;
pushup(rt,l,r);
return ;
}
m = (l+r)>>;
if(L <= m)
update(L,R,c,lson);
if(R > m)
update(L,R,c,rson);
pushup(rt,l,r);
}
int main()
{
int n,cas = ,i,j,l,r,t,num;
char ch[];
int a,b,c,d,col;
scanf("%d",&t);
while(t --)
{
scanf("%d",&n);
num = ;
for(i = ; i <= n; i ++)
{
scanf("%s%d%d%d%d",ch,&a,&b,&c,&d);
if(ch[] == 'R')
col = ;
else if(ch[] == 'G')
col = ;
else
col = ;
mat[num] = node(a,c,b,col);
que[num++] = a;
mat[num] = node(a,c,d,-col);
que[num++] = c;
}
sort(que,que+num);
sort(mat,mat+num);
int k = ;
for(i = ; i < num; i ++)
{
if(que[i] != que[i-])
que[k++] = que[i];
}
memset(cnt,,sizeof(cnt));
memset(sum,,sizeof(sum));
memset(ans,,sizeof(ans));
for(i = ; i < num-; i ++)
{
l = bin(mat[i].lx,k-);
r = bin(mat[i].rx,k-) - ;
if(l <= r)
update(l,r,mat[i].s,,k-,);
for(j = ; j < ; j ++)
ans[j] += ((LL)mat[i+].y - (LL)mat[i].y)*(LL)sum[j][];
}
printf("Case %d:\n",cas++);
printf("%I64d\n",ans[]);
printf("%I64d\n",ans[]);
printf("%I64d\n",ans[]);
printf("%I64d\n",ans[]);
printf("%I64d\n",ans[]);
printf("%I64d\n",ans[]);
printf("%I64d\n",ans[]);
}
return ;
}

HDU 4419 Colourful Rectangle(线段树+扫描线)的更多相关文章

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

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

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

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

  3. HDU 1828“Picture”(线段树+扫描线求矩形周长并)

    传送门 •参考资料 [1]:算法总结:[线段树+扫描线]&矩形覆盖求面积/周长问题(HDU 1542/HDU 1828) •题意 给你 n 个矩形,求矩形并的周长: •题解1(两次扫描线) 周 ...

  4. hdu 1828 Picture(线段树扫描线矩形周长并)

    线段树扫描线矩形周长并 #include <iostream> #include <cstdio> #include <algorithm> #include &l ...

  5. HDU 6096 String 排序 + 线段树 + 扫描线

    String Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) Problem De ...

  6. HDU 5091---Beam Cannon(线段树+扫描线)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...

  7. HDU 1542 Atlantis(线段树扫描线+离散化求面积的并)

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  8. HDU 3265 Posters ——(线段树+扫描线)

    第一次做扫描线,然后使我对线段树的理解发生了动摇= =..这个pushup写的有点神奇.代码如下: #include <stdio.h> #include <algorithm> ...

  9. 【42.49%】【hdu 1542】Atlantis(线段树扫描线简析)

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...

随机推荐

  1. Java和C#运行速度对比:Java比C#快约3倍

    测试条件: Java版本: Java 8, .NET版本:v4.0, Release模式,针对x86平台优化 单线程模式. 测试1:(测试1的代码摘自http://blog.csdn.net/houj ...

  2. js 基本介绍

    ecma  对象 三个包类型  String   ParseInt  ParseDouble instanceof typeof Math  对象 Array Date RegExp -- bom对象 ...

  3. windows下批量删除文件

    FORFILES /P d:\www /D -7 /S /M ex*.log /C "cmd /c del @path" 删除d:\www目录下7天前ex*.log的所有文件 例子 ...

  4. iOS 推荐学习__bridge等ARC知识的好资料

    请下载 iOS5 by Tutorials!写得很好的!

  5. 【JAVA、C++】LeetCode 022 Generate Parentheses

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...

  6. codeforces A. Jeff and Digits 解题报告

    题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...

  7. Eclipse调试:F5、F6、F7、F8

    F5:跳入方法 F6:向下逐行调试 F7:跳出方法 F8:直接跳转到下一个断点 转载自:http://blog.sina.com.cn/s/blog_6271df6f0101d856.html

  8. Android之解析GML并显示

    本例主要实现在APP中解析GML数据并显示 GML,地理标记语言(外语全称:Geography MarkupLanguage.外语缩写:GML),它由开放式地理信息系统协会(外语缩写:OGC)于199 ...

  9. subversion 版本库数据迁移 从一台服务器迁移到另一台新有服务器

    [root@NGINX-APACHE-SVN pro]# pwd /var/www/html/svn/pro [root@NGINX-APACHE-SVN pro]# svnadmin dump /v ...

  10. 改变服务器sshd 的22的端口

    [root@v01-svn-test-server ~]# vi /etc/ssh/sshd_config Port 22 Port 5001 #新增加5001端口给sshd,现在22,5001都是s ...