链接https://vjudge.net/contest/66989#problem/F

坑爹的线段树,一直用区间更新做,做了半天一点眉目都没有,只好搜题解,感觉好堕落,经常不会做就搜题解,以后一定要慢慢克服

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
const int maxn=;
ll value[maxn<<],vis[maxn<<];
void pushdown(int rt)//向下更新
{
if(value[rt]!=-)
{
value[rt<<]=value[rt<<|]=value[rt];//只要向下更新
value[rt]=-;
}
}
void update(int L,int R,int c,int l,int r,int rt)
{
if(L<=l&&r<=R)//区间更新
{
value[rt]=c;
return ;
}
if(value[rt]==c)return ;
if(value[rt]!=-)pushdown(rt);
int m=(l+r)>>;
if(L<=m)update(L,R,c,ls);
if(R>m)update(L,R,c,rs);
}
void query(int l,int r,int rt)
{
if(value[rt]>=)//也有可能是l==r
{
for(int i=l;i<=r;i++)
vis[i]=value[rt];//vis【i】记录i处的颜色
return ;
}
if(l!=r&&value[rt]==-)
{
int m=(l+r)>>;
query(ls);
query(rs);
}
}
int main()
{
int n,ans[];
while(~scanf("%d",&n)){
memset(ans,,sizeof(ans));
memset(vis,-,sizeof(vis));
memset(value,-,sizeof(value));//因为0也算一种颜色,所以初始化-1
for(int i=;i<=n;i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
update(a+,b,c,,,);//不能用0到8000处理
}
query(,,);
int i=;
while(i<maxn){
int color=vis[i],j=i+;
if(vis[i]==-){i++;continue;}//没有颜色
while(vis[j]!=-&&vis[j]==color&&j<maxn)j++;//向前推进直到下一个颜色出现
ans[color]++;
i=j;
}
for(int i=;i<=;i++)
if(ans[i])
printf("%d %d\n",i,ans[i]);
printf("\n");
}
return ;
}

zoj1610线段树区间覆盖的更多相关文章

  1. HDU 4509 湫湫系列故事——减肥记II(线段树-区间覆盖 或者 暴力技巧)

    http://acm.hdu.edu.cn/showproblem.php?pid=4509 题目大意: 中文意义,应该能懂. 解题思路: 因为题目给的时间是一天24小时,而且还有分钟.为了解题方便, ...

  2. [NOI2015] 软件包管理器【树链剖分+线段树区间覆盖】

    Online Judge:Luogu-P2146 Label:树链剖分,线段树区间覆盖 题目大意 \(n\)个软件包(编号0~n-1),他们之间的依赖关系用一棵含\(n-1\)条边的树来描述.一共两种 ...

  3. Mayor's posters POJ - 2528 线段树区间覆盖

    //线段树区间覆盖 #include<cstdio> #include<cstring> #include<iostream> #include<algori ...

  4. POJ - 2528Mayor's posters (离散化+线段树区间覆盖)

    The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...

  5. POJ 2528 Mayor's posters (线段树+区间覆盖+离散化)

    题意: 一共有n张海报, 按次序贴在墙上, 后贴的海报可以覆盖先贴的海报, 问一共有多少种海报出现过. 题解: 因为长度最大可以达到1e7, 但是最多只有2e4的区间个数,并且最后只是统计能看见的不同 ...

  6. 线段树区间覆盖 蛤玮打扫教室(zzuli 1877)

    http://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1877 Description   现在知道一共有n个机房,算上蛤玮一共有m个队员,教练做了m个签,每 ...

  7. HDU1698 Just a Hook(线段树&区间覆盖)题解

    Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for m ...

  8. Mayor's posters 线段树区间覆盖

    题目链接 http://poj.org/problem?id=2528 Description The citizens of Bytetown, AB, could not stand that t ...

  9. HDU 1698 Just a Hook(线段树区间覆盖)

    线段树基本操作练习,防手生 #include <cstdio> #include <cstring> #include <cstdlib> #define lson ...

随机推荐

  1. oracle表空间创建

    /*分为四步 *//*第1步:创建临时表空间  */create temporary tablespace user_temp  tempfile 'D:\oracle\oradata\Oracle9 ...

  2. SQL Server中的Merge关键字 更新表数据

    简介 Merge关键字是一个神奇的DML关键字.它在SQL Server 2008被引入,它能将Insert,Update,Delete简单的并为一句.MSDN对于Merge的解释非常的短小精悍:”根 ...

  3. macaca环境搭建(web 和 android)

    一.安装配置JDK 1.1下载JDK地址http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.h ...

  4. Java开发过程中开发工具Eclipse中导入jar包的过程

    欢迎欣赏我的第二篇随笔.我们在创建好一个动态网站项目之后,如果没有部署maven的情况下,你可以按照以下的方法,直接把要用的jar包导入你的工程中,而不用再部署maven. 例如在使用JDBC编程时需 ...

  5. iOS开发之UIDynamic

    1.概述 什么是UIDynamic? UIDynamic是从iOS 7开始引入的一种新技术,隶属于UIKit框架. 可以认为是一种物理引擎,能模拟和仿真现实生活中的物理现象.比如:重力.弹性碰撞等现象 ...

  6. 小程序新能力-个人开发者尝鲜微信小程序

    个人开发者的福利 微信小程序,刚听到这个新名词的时候,我就兴冲冲的去找入口,看看自己能不能搞个微信小程序的HelloWorld,毕竟能在微信上把自己写的一些小工具跑起来还是满炫酷的. 没想,网上一查, ...

  7. ubuntu用不了root用户:~$ su - root Password: su: Authentication failure怎么办?

    解除root锁定,为root用户设置密码. 打开终端输入:sudo passwd Password: <--- 输入你当前用户的密码 Enter new UNIX password: <- ...

  8. POJ1185炮兵阵地【动态规划】

    炮兵阵地 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 26892   Accepted: 10396 Descriptio ...

  9. Python Selenium设计模式-POM

    前言 本文就python selenium自动化测试实践中所需要的POM设计模式进行分享,以便大家在实践中对POM的特点.应用场景和核心思想有一定的理解和掌握. 为什么要用POM 基于python s ...

  10. UE32修改TAB键为空格键