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 ...
随机推荐
- zabbix图中出现中文乱码问题
我这周部署了zabbix监控服务器,但是配置过程中发现当有中文时,图中的中文会变成方块 如下图所示: 这个问题是由于zabbix的web端没有中文字库,我们最需要把中文字库加上即可 解决办法如下 1. ...
- eclipse开发servlet应用,Tomcat无法访问jpg图片
今天遇到个奇怪的问题,我发现我放在tomcat的webapps文件夹项目下的jpg文件,浏览器无法访问: 以前没有遇到过这个问题,我知道肯定能访问的,因为以前做过相关应用,不知道问题出在哪. 后来我把 ...
- codevs 1242 布局(查分约束+SPFA)
/* 查分约束. 给出的约束既有>= 又有<= 这时统一化成一种 Sb-Sa>=x 建边 a到b 权值为x Sb-Sa<=y => Sa-Sb>=-y 建边 b到a ...
- BestCoder 1st Anniversary
Souvenir Accepts: 1078 Submissions: 2366 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 26 ...
- Android中Action
1 Intent.ACTION_MAIN String: android.intent.action.MAIN 标识Activity为一个程序的开始.比较常用. <activity androi ...
- sql - sum() 和 count() 函数的区别
对sql一直都是蜻蜓点水,突然也觉得对这两个函数的区别有点朦胧,查了一下,在这里说一下: sum():主要用于累加求和. count():主要用于行(记录)的统计.
- iOS: TableView如何刷新指定的cell 或section
//一个section刷新 NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2]; [tableview reloadSections:in ...
- Swift - 31 - 常量参数, 变量参数和inout参数
//: Playground - noun: a place where people can play import UIKit // swift中默认情况下, 传入的参数是不可以修改的, 也就是l ...
- [转]Delphi 快捷键 让你更像高手!!
新一篇: IDFTP 控件使用 >>代码模板 : CTRL+J >>代码整块移动 : CTRL+SHIFT+I(右移) CTRL+SHIFT+U(左移)>>选中窗体 ...
- 重新开始学习javase_对象的摧毁
一.概述(转:@深入理解Java虚拟机:JVM高级特性与最佳实践(最新第二版) ) 经过半个世纪的发展,内存的动态分配与内存回收技术已经相当成熟,一切看起来都进入了“自动化”时代,那为什么我们还要去了 ...