ZOJ 1610——Count the Colors——————【线段树区间替换、求不同颜色区间段数】
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu
Description
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
#include<bits/stdc++.h>
using namespace std;
#define mid (L+R)/2
#define lson rt*2,L,mid
#define rson rt*2+1,mid+1,R
const int maxn = 10000;
int colseg[maxn];
int cnt[maxn];
struct SegTree{
int col;
}segs[maxn*4];
void buildtree(int rt,int L,int R){
segs[rt].col = 0;
if(L == R){
return;
}
buildtree(lson);
buildtree(rson);
}
void PushDown(int rt){
if(segs[rt].col){
segs[rt*2].col = segs[rt*2+1].col = segs[rt].col;
segs[rt].col = 0;
}
}
void Update(int rt,int L,int R,int l_ran,int r_ran,int _col){
if(l_ran <= L && R <= r_ran){
segs[rt].col = _col;
return;
}
PushDown(rt);
if(l_ran <= mid){
Update(lson,l_ran,r_ran,_col);
}
if(r_ran > mid){
Update(rson,l_ran,r_ran,_col);
}
}
void query(int rt,int L,int R){ //把颜色段从树中拿出来,放入colseg数组中
if(segs[rt].col){
for(int i = L; i <= R; i++){
colseg[i] = segs[rt].col;
}
segs[rt].col = 0;
return ;
}
if(L == R) return;
query(lson);
query(rson);
}
int main(){
int n, m;
n = 8001;
while(scanf("%d",&m)!=EOF){
memset(cnt,0,sizeof(cnt));
memset(colseg,0,sizeof(colseg));
buildtree(1,1,n);
int u, v, w;
for(int i = 1; i <= m; i++){
scanf("%d%d%d",&u,&v,&w);
w++;
u++; //把点都看成线段
Update(1,1,n,u,v,w);
}
query(1,1,n);
for(int i = 1; i <= n+10; i++){
if(!colseg[i]) continue;
int j;
for(j = i; j <= n+10 && colseg[i]==colseg[j]; j++) ;
cnt[colseg[i]]++;
i = j - 1; //这里的点都是代表长度为1的单位线段
}
for(int i = 1; i <= n+10; i++){
if(cnt[i]){
printf("%d %d\n",i-1,cnt[i]);
}
}puts("");
}
return 0;
}
ZOJ 1610——Count the Colors——————【线段树区间替换、求不同颜色区间段数】的更多相关文章
- 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(线段树,区间覆盖,单点查询)
Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on ...
- ZOJ 1610 Count the Colors (线段树成段更新)
题意 : 给出 n 个染色操作,问你到最后区间上能看见的各个颜色所拥有的区间块有多少个 分析 : 使用线段树成段更新然后再暴力查询总区间的颜色信息即可,这里需要注意的是给区间染色,而不是给点染色,所以 ...
- ZOJ 1610 Count the Color(线段树区间更新)
描述Painting some colored segments on a line, some previously painted segments may be covered by some ...
- 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 (线段树区间更新与统计)
Painting some colored segments on a line, some previously painted segments may be covered by some th ...
- ZOJ 1610 Count the Colors (线段树区间更新)
题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...
- ZOJ - 1610 Count the Colors(线段树区间更新,单点查询)
1.给了每条线段的颜色,存在颜色覆盖,求表面上能够看到的颜色种类以及每种颜色的段数. 2.线段树区间更新,单点查询. 但是有点细节,比如: 输入: 2 0 1 1 2 3 1 输出: 1 2 这种情况 ...
- Zoj 1610 Count the Colors (线段树+区间更新+暴力计数)
题目大意: 有n次操作,每次都是对一根线中的一段区间进行染色(颜色并不相同),有时候后面的颜色有可能覆盖前面的颜色,问最后涂完色,能看到的颜色有几种,每种颜色有几部分? 解题思路: 这个题目建树的时候 ...
随机推荐
- CHNetRequest网络请求
Paste JSON as Code • quicktype 软件的使用 iOS开发:官方自带的JSON使用 JSON 数据解析 XML 数据解析 Plist 数据解析 NetRequest 网络数据 ...
- Windowns DOS For 循环实例
update_all.bat代码示例: @echo off echo ***************************************************************** ...
- loj #2255. 「SNOI2017」炸弹
#2255. 「SNOI2017」炸弹 题目描述 在一条直线上有 NNN 个炸弹,每个炸弹的坐标是 XiX_iXi,爆炸半径是 RiR_iRi,当一个炸弹爆炸时,如果另一个炸弹所在位置 X ...
- SDUT OJ 顺序表应用6:有序顺序表查询
顺序表应用6:有序顺序表查询 Time Limit: 1000 ms Memory Limit: 4096 KiB Submit Statistic Discuss Problem Descripti ...
- 关于在VS 2013 Reshaper 中不能使用Alt+Enter 的解决
新装Vs 2013 ,感觉还是不错,但是很恶心的是居然,Resharper 万能的快捷键不能用,让洒家真是恶心极了. 通过Google 在StackOverflow 上发现了解决方法,但好像看他的 ...
- WPF:CheckBox竖向的滑块效果
原文:WPF:CheckBox竖向的滑块效果 之前做了一个横向的滑块效果,<WPF:CheckBox滑块效果>,其实我觉得那个不好看,今天又做了一个竖向的玩. <Style Targ ...
- 数据库分库分表配置sharding-jdbc
@Bean(name = "shardingDataSource", destroyMethod = "close") @Qualifier("sha ...
- Exalogic 物理连线
以上图表为Exalogic 1/8配中的思科交换机连线,而1/4配.半配.满配的内置思科交换机连线基本上与以上图表一致.下面对该图表进行简要说明: (1).每台计算节点,只需要从net0上连接一根线到 ...
- 本地localhost:端口号(自己设置的Apache的端口号)打不开问题解决了!开心、哭泣
想不来自己有多蠢!历经4个月再没学,刚开始xampp的端口问题解决不了,系统竟然会自动改回去端口数据(哭晕) 后来一直显示Apache端口80占用,各种百度之后发现单纯浏览器都访问不了localhos ...
- codeforces833B The Bakery
题面传送门 题目大意:将一个长度为n的序列分为k段,使得总价值最大,一段区间的价值表示为区间内不同数字的个数 思路: 显然的dp. 先想到一个朴素的状态转移方程 $dp[i][k]=max(dp[j] ...