题目链接

主要是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中>、>>、>>>三者的区别

    Java,是由Sun Microsystems公司于1995年5月推出的Java程序设计语言和Java平台的总称.用Java实现的HotJava浏览器(支持Java applet)显示了Java的魅力 ...

  2. python - easy_install的安装和使用

    为什么要装easy_install?正常情况下,我们要给Python安装第三方的扩展包,我们必须下载压缩包,解压缩到一个目录,然后命令行或者终端打开这个目录,然后执行python setup.py i ...

  3. cocos2d-x 制作系统公告

    2013-12-15 21:57:33 下载地址:http://download.csdn.net/detail/jackyvincefu/6434549 (摘自:CSDN资源) CTestLayer ...

  4. oracle通过plsql导入dmp数据文件

    首先安装Oracle,新建一个空的数据库mydb 从开始菜单运行cmd控制台:sqlplus "用户名/密码@数据库名 as sysdba"//例如sqlplus sys/admi ...

  5. nodeJS文件路径总结

    文件夹目录F:* test1* tes2* test3* test4* a.html*//例句fs.readFile('../../../a.html', function (err, html) { ...

  6. OGNL表达式struts2标签“%,#,$”

    一.什么是OGNL,有什么特点? OGNL(Object-Graph Navigation Language),大概可以理解为:对象图形化导航语言.是一种可以方便地操作对象属性的开源表达式语言.OGN ...

  7. md5sum 生成 经md5加密后的字符串

    ➜ ~ echo -n 'admin' | md5sum 21232f297a57a5a743894a0e4a801fc3 - ➜ ~ md5sum -h md5sum: invalid option ...

  8. linux tricks 之 FIELD_SIZEOF.

    ------------------------------------------- 本文系作者原创, 欢迎大家转载! 转载请注明出处:netwalker.blog.chinaunix.net -- ...

  9. html select 下拉箭头隐藏

    html select 下拉箭头隐藏 <!DOCTYPE html> <html> <head lang="en"> <meta char ...

  10. PHP 5.4中的traits特性

    Trait 是 PHP5. 中的新特性,是 PHP 多重继承的一种解决方案.例如,需要同时继承两个 Abstract Class, 这将会是件很麻烦的事情,Trait 就是为了解决这个问题. 简单使用 ...