zoj 1610
Count the Colors
Time Limit: 2 Seconds Memory Limit: 65536 KB
Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones.
Your task is counting the segments of different colors you can see at last.
Input
The first line of each data set contains exactly one integer n, 1 <= n <= 8000, equal to the number of colored segments.
Each of the following n lines consists of exactly 3 nonnegative integers separated by single spaces:
x1 x2 c
x1 and x2 indicate the left endpoint and right endpoint of the segment, c indicates the color of the segment.
All the numbers are in the range [0, 8000], and they are all integers.
Input may contain several data set, process to the end of file.
Output
Each line of the output should contain a color index that can be seen from the top, following the count of the segments of this color, they should be printed according to the color index.
If some color can't be seen, you shouldn't print it.
Print a blank line after every dataset.
Sample Input
5
0 4 4
0 3 1
3 4 2
0 2 2
0 2 3
4
0 1 1
3 4 1
1 3 2
1 3 1
6
0 1 0
1 2 1
2 3 1
1 2 0
2 3 0
1 2 1
Sample Output
1 1
2 1
3 1
1 1
0 2
1 1
题目大意是给定区间0~8000进行涂色,之后输出各个颜色的段数(不是被涂色点的数量,而是区间量)。用col记录色彩号码,没涂色时记录-1,该区间涂了多种颜色时记录-2。注意,在算颜色段数的时候要用全局变量temp记录上一段的颜色,以此判断是否加1。
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
int n,col[32100],num[8100],temp=-1;
void pushdown(int k)
{
if(col[k]>=0){
col[k<<1]=col[k<<1|1]=col[k];
col[k]=-2;
}
}
void build(int s,int t,int k)
{
col[k]=-1;
if(s+1==t){
num[s]=0;
return;
}int m=(s+t)>>1;
build(s,m,k<<1);
build(m,t,k<<1|1);
}
void update(int s,int t,int k,int l,int r,int c)
{
if(col[k]==c)return;
if(l<=s&&t<=r){
col[k]=c;
return;
}pushdown(k);
int m=(s+t)>>1;
if(l<m)update(s,m,k<<1,l,r,c);
if(m<r)update(m,t,k<<1|1,l,r,c);
col[k]=-2;
}
void query(int s,int t,int k)
{
if(s==t)return;
if(col[k]==-1){
temp=-1;
return;
}
if(col[k]!=-2){
if(col[k]!=temp){
num[col[k]]++;
temp=col[k];
}
return;
}
if(s+1!=t){
int m=(s+t)>>1;
query(s,m,k<<1);
query(m,t,k<<1|1);
}
}
int main()
{
freopen("data.txt","r",stdin);
freopen("test.out","w",stdout);
while(~scanf("%d",&n)){
build(0,8000,1);
int maxnum=0;
for(;n;n--){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
update(0,8000,1,a,b,c);
maxnum=max(maxnum,c);
}temp=-1;
query(0,8000,1);
for(int i=0;i<=maxnum;i++)
if(num[i])printf("%d %d\n",i,num[i]);
puts("");
}
return 0;
}
zoj 1610的更多相关文章
- ZOJ 1610 Count the Colors (线段树区间更新)
题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...
- zoj 1610 Count the Colors
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=610 Count the Colors Time Limit:2000MS ...
- ZOJ 1610——Count the Colors——————【线段树区间替换、求不同颜色区间段数】
Count the Colors Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Subm ...
- 线段树区间染色 ZOJ 1610
Count the Colors ZOJ - 1610 传送门 线段树区间染色求染色的片段数 #include <cstdio> #include <iostream> #in ...
- ZOJ 1610.Count the Colors-线段树(区间染色、区间更新、单点查询)-有点小坑(染色片段)
ZOJ Problem Set - 1610 Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting s ...
- zoj 1610 Count the Colors(线段树延迟更新)
所谓的懒操作模板题. 学好acm,英语很重要.做题的时候看不明白题目的意思,我还拉着队友一块儿帮忙分析题意.最后确定了是线段树延迟更新果题.我就欣欣然上手敲了出来. 然后是漫长的段错误.... 第一次 ...
- (线段树) Count the Colors --ZOJ --1610
链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82832#problem/F http://acm.zju.edu.cn/onli ...
- zoj 1610 Count the Colors 线段树区间更新/暴力
Count the Colors Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...
- ZOJ 1610 Count the Colors【题意+线段树区间更新&&单点查询】
任意门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Count the Colors Time Limit: 2 ...
- zoj 1610 Count the Colors 【区间覆盖 求染色段】
Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on ...
随机推荐
- Android Property Animation动画
3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中又引入了一个新的动画系统:property animation,这三 ...
- JavaScript学习04 对象
JavaScript学习04 对象 默认对象 日期对象Date, 格式:日期对象名称=new Date([日期参数]) 日期参数: 1.省略(最常用): 2.英文-数值格式:月 日,公元年 [时:分: ...
- Ida双开定位android so文件
Ida双开定位的意思是先用ida静态分析so文件,然后再开一个ida动态调试so文件.因为在动态调试中ida并不会对整个动态加载的so文件进行详细的分析,所以很多函数并无法识别出来.比如静态分析中有很 ...
- MTK 常见的编译命令
1: ./mk n(r) kernel; ./mk bootimage;当修改build-in 到kernel相关代码时,要使用此命令,具体文件参考如下: alps/kernel/ alps/medi ...
- mysql java Cannot find the driver in the classpath!
确保你的mysql-connector-java有没有配置好, 如何配置: 从oracle上把mysql-connector-java下下来放到java_home里面的extensions里面,然后在 ...
- 【代码笔记】iOS-竖排文字
一,代码. - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. ...
- Android对应用程序签名
1.首先签名是个什么东西. 应用程序签名就是为你的程序打上一种标记,来作为你自己的标识. 2.为什么要进行数字签名 这是Android系统的要求,每一个应用程序必要要经过数字签名才可能安装到系统中,能 ...
- symfony2 twig模板引擎
1.基本语法 Says something:{{ }} Does something:{% %} Comment something:{# #} {% extends "App ...
- 编写Java应用程序。首先定义一个描述银行账户的Account类,包括成员变 量“账号”和“存款余额”,成员方法有“存款”、“取款”和“余额查询”。其次, 编写一个主类,在主类中测试Account类的功能
package com.hanqi.test; //银行账号 public class account { private String zhanghao;//账号 //私有余额 private do ...
- EF深入系列--细节
1.在调试的时候,查看EF生成的SQL语句 在Context类的构造函数中添加以下代码,就可以在调试的时候在[输出]窗口中看到SQL语句 this.Database.Log = s => Sys ...