Count the Colors ZOJ - 1610 区间颜色覆盖
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
const int MAXN=;
struct Node
{
int l,r;
int color;
}tr[MAXN*];
int color[MAXN];
int temp;
void build(int i,int l,int r)
{
tr[i].l=l;
tr[i].r=r;
//-1表示没有颜色
tr[i].color=-;
if(l+==r)
return;
int mid=((l+r)>>);
build(i<<,l,mid);
build((i<<)|,mid,r);
}
void insert(int i,int l,int r,int c)
{
if(l==r)
return;
if(tr[i].color==c)
return;
if(l<=tr[i].l&&r>=tr[i].r)
{
tr[i].color=c;
return;
}
//存在颜色,往下更新
if(tr[i].color>=)
{
tr[i<<].color=tr[i].color;
tr[(i<<)|].color=tr[i].color;
//表示有多种颜色
tr[i].color=-;
}
int mid=((tr[i].l+tr[i].r)>>);
if(r<=mid)
insert(i<<,l,r,c);
else if(l>=mid)
insert((i<<)|,l,r,c);
else
{
insert(i<<,l,mid,c);
insert((i<<)|,mid,r,c);
}
tr[i].color=-;
}
//统计各颜色的段数
void query(int i)
{
if(tr[i].color==-)
{
temp=-;
return;
}
if(tr[i].color!=-)
{
//temp存的是前一段的颜色
if(tr[i].color!=temp)
{
color[tr[i].color]++;
temp=tr[i].color;
}
return;
}
if(tr[i].l+!=tr[i].r)
{
query(i<<);
query((i<<)|);
}
}
int main()
{
int n,a,b,c;
int Max;
while(scanf("%d",&n)!=EOF)
{
build(,,);
Max=;
while(n--)
{
scanf("%d%d%d",&a,&b,&c);
insert(,a,b,c);
if(c>Max)
Max=c;
}
temp=-;
memset(color,,sizeof(color));
query();
for(int i=;i<=Max;i++)
if(color[i])
printf("%d %d\n",i,color[i]);
printf("\n");
}
return ;
}
Count the Colors ZOJ - 1610 区间颜色覆盖的更多相关文章
- F - Count the Colors - zoj 1610(区间覆盖)
有一块很长的画布,现在想在这块画布上画一些颜色,不过后面画的颜色会把前面画的颜色覆盖掉,现在想知道画完后这块画布的颜色分布,比如 1号颜色有几块,2号颜色有几块.... *************** ...
- (线段树) 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 ZOJ - 1610 线段树染色(染区间映射)
题意:给一段0-8000的线段染色 问最后 颜色x 有几段 题解:标准线段树 但是没有push_up 最后查询是单点按顺序查询每一个点 考虑过使用区间来维护不同的线段有多少种各色的线段 思路是 ...
- ZOJ 1610 Count the Colors(线段树,区间覆盖,单点查询)
Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on ...
- 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 ...
- 线段树区间染色 ZOJ 1610
Count the Colors ZOJ - 1610 传送门 线段树区间染色求染色的片段数 #include <cstdio> #include <iostream> #in ...
- F - Count the Colors
F - Count the Colors ZOJ - 1610 思路:调了一个小时,但是发现自己线段树木有写错,颜色统计出了错误.但是不明白自己颜色统计为什么错了. 求大佬指点迷津.思路很简单,就 ...
随机推荐
- openstack 架构
openstack 概念架构: openstack逻辑架构 常见的架构:
- 如何写出优雅的Python代码?
有时候你会看到很Cool的Python代码,你惊讶于它的简洁,它的优雅,你不由自主地赞叹:竟然还能这样写.其实,这些优雅的代码都要归功于Python的特性,只要你能掌握这些Pythonic的技巧,你一 ...
- Codeforces_731_A
http://codeforces.com/problemset/problem/731/A 每次操作总共4种情况,判断一下就好了. #include<iostream> #include ...
- ARTS Week 11
Jan 6, 2020 ~ Jan 12, 2020 Algorithm Problem 108 Convert Sorted Array to Binary Search Tree (将有序数组转化 ...
- c++ 中数组的引用
在C++里,数组也是可以引用的. 代码如下: char str1[] = "abcde"; ] = str1; 解读第二句代码,括号的优先级最高,'str2'首先与'&'相 ...
- c#学习笔记之委托
委托 最近自己在调试C#项目,发现经常可以看到委托和lambda表达式,各种花里胡哨的写法把我给整的云里雾里的,于是自己特意花了一点功夫来整理关于delegate的相关知识,方便自己日后查阅. 何为委 ...
- JavaScript 构造函数的继承
JavaScript 构造函数的继承 在上一篇文章中讲述了 JS 对象.构造函数以及原型模式,这篇文章来讨论下 JavaScript 的继承 继承是 OO 语言中的一个最为人津津乐道的概念.许多 OO ...
- 开发时从宿主机连接容器中的MySQL
从宿主机连接Docker容器中的MySQL 刚接触Docker,电脑安装Docker后,使用docker命令pull了一个MySQL5.6的Docker镜像,之后docker run启动创建容器. 可 ...
- k8s系列---StorageClass
介绍这个概念前,需要提前知道存储卷pv/pvc之类的概念. 之前的文章有关于EFK日志系统的介绍,里面的环境是测试环境,完全按照教程一步步的操作,甚至注释掉了持久化存储,当真正线上部署时,又抓虾,打开 ...
- zabbix-mysql迁移分离
io过高,迁移mysql 停掉zabbix 导出数据库的zabbix库 导入到新机器,并启动mysql 1:修改zabbix_server.conf文件里DB相关的地址,用户名和密码. vim /et ...