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 ...
随机推荐
- 【iOS控制器跳转时,NavigationBar有阴影动画闪过的解决办法】
如题,push控制器时,由于默认的控制器view是黑色,push到这个控制器时,navigationBar(默认是透明效果)后面有一个黑色阴影一闪而过,解决办法将navigationBar设为图片填充 ...
- JavaScript--动态更改CSS样式
JavaScript太强大了,虽然是弱语言,不过一点都不输于Java 可以自行设置随机数,来动态更改CSS样式,每一次都是不一样的感觉,这个小功能挺实用的 <!DOCTYPE html> ...
- jQuery的选择器中的通配符[id^='code']或[name^='code']
这两天在做一个专题的时候遇到了一个通配符的问题 //弹层操作$(function(){ //视频播放 $("a[href^='#video']").each(function(in ...
- EXT ajax简单实例
转载:http://www.cnblogs.com/xiepeixing/archive/2012/10/24/2736751.html EXT ajax request是ext中对于ajax请求的实 ...
- linux 'more' command.
more命令,功能类似 cat ,cat命令是整个文件的内容从上到下显示在屏幕上. more会以一页一页的显示方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会 ...
- web.xml配置详解 (及<context-param>配置作用 )
http://blog.csdn.net/guihaijinfen/article/details/8363839 <context-param>配置作用 http://blog.csdn ...
- 了解<hx>标签,为你的网页添加标题
文章的段落用<p>标签,那么文章的标题用什么标签呢?在本节我们将使用<hx>标签来制作文章的标题.标题标签一共有6个,h1.h2.h3.h4.h5.h6分别为一级标题.二级标题 ...
- cas sso单点登录系列7_ 单点登录cas常见问题系列汇总
转:http://blog.csdn.net/matthewei6/article/details/50709252 单点登录cas常见问题(一) - 子系统是否还要做session处理?单点登录ca ...
- FFMPEG 截取RTMP直播流图片命令
CentOS 6.5 yum安装FFMPEG步骤 1. 手动添加yum源配置 vi /etc/yum.repos.d/dag.repo [dag] name=Dag RPM Repository ...
- JavaScript-学习一字符串
字符串可以存储一系列字符,如 "John Doe". 字符串可以是插入到引号中的任何字符.你可以使用单引号或双引号: 用于字符串的 + 运算符 + 运算符用于把文本值或字符串变量加 ...