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 ...
随机推荐
- maven 启动忽略test
两种方法 1,--命令 mvn install -Dmaven.test.skip=true 2.pom.xml 文件 在tomcat 下面的pom.xml 文件里面加上如下 <!-- ski ...
- Android开发手记(20) 数据存储五 网络存储
Android为数据存储提供了五种方式: 1.SharedPreferences 2.文件存储 3.SQLite数据库 4.ContentProvider 5.网络存储 安卓的网络存储比较简单,因为A ...
- 强引用,弱引用,4种Java引用浅解(涉及jvm垃圾回收)
http://www.jb51.net/article/49085.htm http://www.jb51.net/article/49085.htm
- 使用C++11 实现的线程池
最近打算做一个服务器端程序,每来一个客户端请求新开一个线程进行处理.在网上查了一些资料后,准备使用线程池来做这个东西.使用C++11新的库处理想线程问题比以前简单了许多,在网上找到一份线程池的实现,h ...
- 离线安装maven,重新打开eclipse报错处理方法
报错截图如下 1.eclipse 添加 jre Window -> Preferences -> Java -> Installed JREs If you can’t find a ...
- JQUERY1.9学习笔记 之基本过滤器(八) 最后元素选择器
最后元素选择器 jQuery( ":last" ) 描述:选择与之匹配的最后元素. 例:选择表格的最后一行. <!DOCTYPE html><html lang= ...
- localstorage || globalStorage || userData
globalStorage 这个也是html5中提出来,在浏览器关闭以后,使用globalStorage存储的信息仍能够保留下来,并且存储容量比IE的userdata大得多,一个域下面是5120k.和 ...
- python运维开发之第七天
一.面向对象编程进阶 1.静态方法 @staticmethod 名义上归类管理,实际上跟类没什么关系 在静态方法里,访问不了类或实例中的任何属性 class Static_method(object) ...
- css阴影
文字阴影:text-shadow:[颜色 x轴 y轴 模糊半径],[颜色 x轴 y轴 模糊半径]... 区域阴影:box-shadow:[颜色 x轴 y轴 模糊半径],[颜色 x轴 y轴 模糊半径]. ...
- jdom学习:读取xml文件
用JDOM读取XML文件需先用org.jdom.input.SAXBuilder对象的build()方法创建Document对象,然后用Document类.Element类等的方法读取所需的内容.IB ...