F - Count the Colors - zoj 1610(区间覆盖)
|
Segmentation Fault
|
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define Lson root<<1,L,tree[root].Mid()
#define Rson root<<1|1,tree[root].Mid()+1,R const int maxn = ; struct Hook{int l, r, c;}p[maxn];
struct Tree{
int L, R;
int color;//记录颜色
int Mid(){return (L+R)/;}
}tree[maxn*];
int Color[maxn]; void CoverColor(int L, int R, int e)//把区间LR涂成颜色e
{
for(int i=L; i<=R; i++)
Color[i] = e;
} void Build(int root, int L, int R)
{
tree[root].L = L, tree[root].R = R;
//0代表没有被颜色覆盖,1代表未覆盖,2代表子树有被别的颜色覆盖
tree[root].color = ; if(L == R)return ; Build(Lson);
Build(Rson);
}
void Up(int root)
{
if(tree[root].L != tree[root].R)
if(tree[root<<].color == && tree[root<<|].color == )
tree[root].color = ;
}
void Insert(int root, int L, int R, int e)
{
if(tree[root].color == )return ; if(tree[root].L == L && tree[root].R == R && !tree[root].color)
{
tree[root].color = ;
CoverColor(L, R, e);
return ;
}
tree[root].color = ; if(R <= tree[root].Mid())
Insert(root<<, L, R, e);
else if(L > tree[root].Mid())
Insert(root<<|, L, R, e);
else
{
Insert(Lson, e);
Insert(Rson, e);
} Up(root);
}
int main()
{
int N; while(scanf("%d", &N) != EOF)
{
int i, ans[maxn] = {}; for(i=; i<=N; i++)
scanf("%d%d%d", &p[i].l, &p[i].r, &p[i].c); Build(, , maxn-);
memset(Color, -, sizeof(Color)); for(i=N; i>; i--)//因为给的是紧密区间,而建的树点的,所以把左边的+1,变成点覆盖的
Insert(, p[i].l+, p[i].r, p[i].c); for(i=; i<maxn; i++)
{
if( Color[i]!=- && (!i || Color[i]!=Color[i-]) )
ans[Color[i]]++;
} for(i=; i<maxn; i++)if(ans[i])
printf("%d %d\n", i, ans[i]);
printf("\n");
} return ; }
F - Count the Colors - zoj 1610(区间覆盖)的更多相关文章
- F - Count the Colors ZOJ - 1610 线段树染色(染区间映射)
题意:给一段0-8000的线段染色 问最后 颜色x 有几段 题解:标准线段树 但是没有push_up 最后查询是单点按顺序查询每一个点 考虑过使用区间来维护不同的线段有多少种各色的线段 思路是 ...
- Count the Colors ZOJ - 1610 区间颜色覆盖
#include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> ...
- ZOJ 1610 Count the Colors(线段树,区间覆盖,单点查询)
Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on ...
- (线段树) Count the Colors --ZOJ --1610
链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82832#problem/F http://acm.zju.edu.cn/onli ...
- F - Count the Colors
F - Count the Colors ZOJ - 1610 思路:调了一个小时,但是发现自己线段树木有写错,颜色统计出了错误.但是不明白自己颜色统计为什么错了. 求大佬指点迷津.思路很简单,就 ...
- zoj 1610 Count the Colors 线段树区间更新/暴力
Count the Colors Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...
- 线段树专题—ZOJ1610 Count the Colors(涂区间,直接tag标记)
Painting some colored segments on a line, some previously painted segments may be covered by some th ...
- ZOJ1610 Count the Colors —— 线段树 区间染色
题目链接:https://vjudge.net/problem/ZOJ-1610 Painting some colored segments on a line, some previously p ...
- F - Count the Colors(线段树)
Painting some colored segments on a line, some previously painted segments may be covered by some th ...
随机推荐
- DOM Style样式对象的详细用法
DOM Style样式对象的详细用法 HTML Style样式比较复杂,相应访问.修改方法也有所差异.参考相关资料,整理如下. 典型Html文件如下,有三种定义方式. <head> ...
- http方法
http method(方法):1.get 从服务器获取资源2.post 向服务器发送资源3.put 向服务器推送资源4.delete 告诉服务器删除某个资源5.head 告诉服务器返回数据时不需要返 ...
- HTTPS双向认证
生成证书 openssl genrsa -des3 -out server.key 2048 openssl req -new -x509 -key server.key -out ca.crt -d ...
- 【转】overload与override的区别
[转]overload与override的区别 override(重写,覆盖) 1.方法名.参数.返回值相同. 2.子类方法不能缩小父类方法的访问权限. 3.子类方法不能抛出比父类方法更多的异常(但子 ...
- Activity之间的数据传递(Arraylist)
1.使用Serialiable方法 实现序列化 2.使用Parcelable方法(这是android自己封装的类) Parcel类是封装数据的容器,封装后的数据通过Intent和IPC传递 实 ...
- 你好,C++(32) 类是对现实世界的抽象和描述 6.2.1 类的声明和定义
6.2 类:当C++爱上面向对象 类这个概念是面向对象思想在C++中的具体体现:它既是封装的结果,同时也是继承和多态的载体.因此,要想学习C++中的面向对象程序设计,也就必须从“类”开始. 6.2. ...
- js实现输入验证码
html部分: <div> <input type="text" id="input" /> <input type=" ...
- js中的 window.location、document.location、document.URL 对像的区别(转载)
原文:http://www.cr173.com/html/18417_1.html 当我们需要对html网页进行转向的时候或是读取当前网页的时候可以用到下面三个对像: window.location. ...
- table表格cellspacing与cellpadding属性
cellspacing属性 用来指定表格各单元格之间的空隙. cellpadding属性 用来指定单元格内容与单元格边界之间的空白距离的大小. 此属性的参数值也是数字,表示单元格内容与上下边界之间空白 ...
- python运维开发之第七天
一.面向对象编程进阶 1.静态方法 @staticmethod 名义上归类管理,实际上跟类没什么关系 在静态方法里,访问不了类或实例中的任何属性 class Static_method(object) ...