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. Python学习,第八课 - 函数

    本次讲解函数,由于内容比较多,小编列了个大纲,主要有一下内容: 1. 函数基本语法及特性 2. 函数参数 3.局部变量 4. 返回值 5.嵌套函数 6.递归 7.匿名函数 8.高阶函数 9.内置函数 ...

  2. 找不到文件异常java.io.IOException: Resource [classpath:shiro.ini] could not be found.

    情景 tomcat启东时,老是报错,在classpath下找不到配置文件,但是配置文件已经放在resource目录下了 解决方案 出现该异常的原因,是因为新建的conf文件夹,识别不了,因为没有设置成 ...

  3. 微信小程序 客户端时间 与 服务端时间

    服务端时间 db.serverDate(); 在操作数据库,上传数据的时候可以使用服务端时间 wx.cloud.init();//初始化云 const db = wx.cloud.database() ...

  4. ros之自定义服务数据

    如何自定义服务数据 string name Uint8 age Uint8 sex Uint8 unknown =0 Uint8 male =1 Uint8 female = 2 (上面的是Reque ...

  5. PT教程 - 应用系列 - ECO修复Timing(理论+实践+脚本分享)

    ​本文转自:自己的微信公众号<集成电路设计及EDA教程> <PT教程 - 应用系列 - ECO修复Timing(理论+实践+脚本分享)> 这篇推文讲一下数字IC设计中的post ...

  6. mplayer的参数

    播放文件 使用 MPlayer 播放媒体文件最简单的方式是: mplayer <somefile>  MPlayer 会自动检测文件的类型并加以播放,如果是音频文件,则会在命令行中显示该播 ...

  7. shell命令之一天一见

    一.在统计行数时常要用的到命令包括 w.c.l, 在这里做个简单的介绍. 语法:wc [选项] 文件… 说明:该命令统计给定文件中的字节数.字数.行数.如果没有给出文件名,则从标准输入读取.wc同时也 ...

  8. DHCP服务器配置及测试

    1 DHCP服务器简介 DHCP(Dynamic Host Configuration Protocol),动态主机配置协议,DHCP 协议主要是用来自动为局域网中的客户机分配TCP/IP 信息的网络 ...

  9. HDU3836 Equivalent Sets (Tarjan缩点+贪心)

    题意: 给你一张有向图,问你最少加多少条边这张图强连通 思路: 缩点之后,如果不为1个点,答案为出度为0与入度为0的点的数量的最大值 代码: #include<iostream> #inc ...

  10. WARNING OGG-00706 Failed to add supplemental log group on table

    在配置OGG时,需要给同步的表添加补充日志,在ggsci命令行执行 add trandata user.table   SQL> desc jack.t1 Name Null? Type --- ...