Count the Colors ZOJ - 1610

传送门

线段树区间染色求染色的片段数

#include <cstdio>
#include <iostream>
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
#define ll long long
#define P pair<int,int>
const ll INF=1e18;
const int N=8000+10;
int ans[N];
struct SegmentTree{
int l,r;
int dat;
}t[N*4];
void build(int p,int l,int r)
{
t[p].l = l;
t[p].r = r;
t[p].dat = -1;
if(t[p].l == t[p].r){t[p].dat = -1;return ;}
int mid = (l+r)/2;
build(p*2,l,mid);
build(p*2+1,mid+1,r);
}
void spread(int p)
{
if(t[p].dat>=0)
{
t[p*2].dat = t[p].dat;
t[p*2+1].dat = t[p].dat;
t[p].dat = -1;
}
}
void change(int p,int l,int r,int v)
{
if(l <= t[p].l && t[p].r <= r)
{
t[p].dat = v;
return ;
}
int mid = (t[p].l+t[p].r)/2;
spread(p);
if(l<=mid) change(p*2,l,r,v);
if(r>mid) change(p*2+1,l,r,v);
}
int ask(int p,int l,int r)
{
if(t[p].l == t[p].r)
{
return t[p].dat;
}
int mid = (t[p].l+t[p].r)/2;
spread(p);
if(l<=mid) return ask(p*2,l,r);
if(r>mid) return ask(p*2+1,l,r);
}
int n;
int main()
{
ios::sync_with_stdio(false);
while(cin >> n)
{
build(1,1,8000);
for(int i=0;i<=8000;i++)
{
ans[i] = 0;
}
for(int i=1;i<=n;i++)
{
int l,r,d;
cin >> l >> r >> d;
change(1,l+1,r,d);
}
int last = -1,now;
for(int i=1;i<=8000;i++)
{
now = ask(1,i,i);
if(now!=last && now!=-1)
ans[now]++;
last = now;
}
for(int i=0;i<=8000;i++)
{
if(ans[i])
{
cout << i <<" "<< ans[i] <<"\n";
}
}
cout << "\n";
}
return 0;
}

线段树区间染色 ZOJ 1610的更多相关文章

  1. HDU3974 Assign the task(多叉树转换为线段+线段树区间染色)

    题目大意:有n个人,给你他们的关系(老板和员工),没有直属上司的人就是整个公司的领导者,这意味着n个人形成一棵树(多叉树).当一个人被分配工作时他会让他的下属也做同样的工作(并且立即停止手头正在做的工 ...

  2. hdu 5023(线段树区间染色,统计区间内颜色个数)

    题目描述:区间染色问题,统计给定区间内有多少种颜色? 线段树模板的核心是对标记的处理 可以记下沿途经过的标记,到达目的节点之后一块算,也可以更新的时候直接更新到每一个节点 Lazy操作减少修改的次数( ...

  3. POJ 1436 (线段树 区间染色) Horizontally Visible Segments

    这道题做了快两天了.首先就是按照这些竖直线段的横坐标进行从左到右排序. 将线段的端点投影到y轴上,线段树所维护的信息就是y轴区间内被哪条线段所覆盖. 对于一条线段来说,先查询和它能相连的所有线段,并加 ...

  4. HDU 5023线段树区间染色,统计区间内颜色个数

    这个也是一个线段树的模板 #include<iostream> #include<string.h> #include<algorithm> #include< ...

  5. ZOJ1610 Count the Colors —— 线段树 区间染色

    题目链接:https://vjudge.net/problem/ZOJ-1610 Painting some colored segments on a line, some previously p ...

  6. HDU1698 Just a Hook —— 线段树 区间染色

    题目链接:https://vjudge.net/problem/HDU-1698 In the game of DotA, Pudge’s meat hook is actually the most ...

  7. hdu1556 Color the ball 线段树区间染色问题

    都是老套路了,如果n=5,要把区间[1,4]染色,可以递归去染区间[1,3]和区间[4,4],如果区间相等就自加,不相等继续递归寻找对应区间. 打印结果时,把所有到达叶节点包含i的区间值相加,就是最后 ...

  8. POJ 2528 Mayor's posters(线段树区间染色+离散化或倒序更新)

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 59239   Accepted: 17157 ...

  9. ZOJ 1610.Count the Colors-线段树(区间染色、区间更新、单点查询)-有点小坑(染色片段)

    ZOJ Problem Set - 1610 Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting s ...

随机推荐

  1. linux--->阿里云centos6.9安装yii2报错

    阿里云centos6.9安装yii2报错 错误显示:Warning: require(/vendor/autoload.php): failed to open stream: No such fil ...

  2. Windows 10搭建Apache2.4 + PHP7 + MySQL环境

    一.准备 1.资源 Apache https://www.apachelounge.com/download/ PHP http://windows.php.net/download#php-7.0 ...

  3. Hexo+coding实现自动化部署

    前言 昨天写了一篇利于云环境写博客,但是让群里大佬们看了下.评论道:"写的不错,但还是觉得这个云环境太繁琐了,没有CI/CD自动化部署方便".于是我便百度查了下,网上文章大部分是通 ...

  4. Struts(六)

    JSON(JavaScript Object Notation)    1.一种轻量级的数据交换格式    2.通常用于在客户端和服务器之间传递数据    3.jQuery的所有参数都是以JSON格式 ...

  5. CSS Module解决全局或本地使用@keyframes无效问题

    最近使用CSSModule开发react项目,遇到一个问题,使用@keyframes无效,问题如下 /** less + css module **/ :global { .effect-bottom ...

  6. 视觉slam十四讲ch5 joinMap.cpp 代码注释(笔记版)

    #include <iostream> #include <fstream> using namespace std; #include <opencv2/core/co ...

  7. CCF_201312-4_有趣的数

    dp题,dp[i][j]代表i位数,j状态的数量.其中,j 的状态表示值有6种. 0 1 2     √ j = 0 3 01 02   √ j = 1 03 12 13 23   √ j = 2 0 ...

  8. 关于Icon,Image,ImageIcon的简单的对比参考

    Icon: Icon位于javax.swing包中,它是一个接口 public interface Icon,介绍为:一个小的固定大小的图片,通常用于装饰组件 有三个方法: int getIconHe ...

  9. python笔记带你走向测试开发之路-第一篇(数据类型之数字,序列)

    数字 数字的类型 数字是 Python中比较常用的数据类型,数字有可以分为: 整型 int如 1,2,3 浮点型 float如 2.1,3.5 长整型 long如 3L,需要注意的是 Python2. ...

  10. Mysql 5.7.18:主从复制,io优化

    #目录 #挂盘#时间同步#master节点,进行如下操作: #下载安装 #初始化 #配置文件 #开机启动 #服务启动 #初始数据库#slave节点,进行如下操作: #下载安装 #初始化 #配置文件 # ...