题目链接

主要是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. abstract class和interface的区别

    1. 引言 2. 概念引入 ●什么是接口? 接口是包含一组虚方法的抽象类型,其中每一种方法都有其名称.参数和返回值.接口方法不能包含任何实现,CLR允许接口可以包含事件.属性.索引 器.静态方法.静态 ...

  2. 《ASP.NET1200例》ListView 控件与DataPager控件的结合<一>

    分页     在前一部分开始时介绍的原 HTML 设计中内含分页和排序,所以根据规范完整实现该网格的任务尚未完成.我们先分页,然后再排序. ListView 控件中的分页通过引入另一个新控件 Data ...

  3. css用标签选择器在本页写样式

    <title>静夜思</title><style type="text/css">p{ color:#ff0000;   font-size:2 ...

  4. 36.在字符串中删除特定的字符[Delete source from dest]

    [题目] 输入两个字符串,从第一字符串中删除第二个字符串中所有的字符.例如,输入”They are students.”和”aeiou”,则删除之后的第一个字符串变成”Thy r stdnts.”. ...

  5. Java for LeetCode 169 Majority Element

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  6. codeforces A. The Wall 解题报告

    题目链接:http://codeforces.com/problemset/problem/340/A 这道题目理解不难,就是在[a, b]区间内,找出同时能够被x和y整除的个数.第一次想当然的开了两 ...

  7. Tomcat 解决The code of method _jspService(HttpServletRequest, HttpServletResponse) is exceeding the 65535 bytes limit

    解法: 修改tomcat下的web.xml,     搜索:JspServlet, 增加: <init-param> <param-name>mappedfile</pa ...

  8. linux之间文件传输问题

    如果linux服务器使用了秘钥登陆,可以先关闭秘钥登陆 http://blog.chinaunix.net/uid-23634108-id-2393471.html 然后:scp -P 端口号  no ...

  9. Java查询网址

    Java在线帮助文档: http://docs.oracle.com/javase/8/docs/technotes/guides/desc_jdk_structure.html Java小知识讲解: ...

  10. mysql忘记密码修改方法

    1.干掉mysqld进程 kill -TERM mysqld 2.使用下面命令启动mysqld /usr/bin/mysqld_safe --skip-grant-tables & 3.新开一 ...