POJ 1610 Count the Colors
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
线段树区间更新,一段一段更新,并不是点
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int vis[];
int li,ri,w;
int pos[];
int ans[];
void pushdown(int node)
{
if(vis[node]!=-)
{
vis[node<<]=vis[node];
vis[node<<|]=vis[node];
vis[node]=-;
}
}
void update(int ll,int rr,int val,int l,int r,int node)
{
if(ll<=l && rr>=r)
{
vis[node]=val;
return ;
}
pushdown(node);
int mid=(l+r)>>;
if(ll<=mid) update(ll,rr,val,l,mid,node<<);
if(rr>mid) update(ll,rr,val,mid+,r,node<<|);
}
void query(int l,int r,int node)
{
if(vis[node]>=)
{
for(int i=l;i<=r;i++)
ans[i]=vis[node];
return ;
}
if(vis[node]==- && l!=r)
{
int mid=(l+r)>>;
query(l,mid,node<<);
query(mid+,r,node<<|);
}
}
int main()
{
int m;
while(scanf("%d",&m)!=EOF)
{
memset(vis,-,sizeof(vis));
memset(pos,,sizeof(pos));
memset(ans,-,sizeof(ans));
for(int i=;i<m;i++)
{
scanf("%d%d%d",&li,&ri,&w);
if(li>=ri) continue;
update(li+,ri,w,,,);
}
query(,,);
int i=;
while(i<)
{
int coo=ans[i],j=i+;
if(coo==-){i++;continue;}
while(j< && ans[j]==coo && ans[j]!=-)
{
j++;
}
pos[coo]++;
i=j;
}
for(int i=;i<;i++)
{
if(pos[i]) printf("%d %d\n",i,pos[i]);
}
printf("\n");
}
return ;
}
POJ 1610 Count the Colors的更多相关文章
- 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
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: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...
- 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 【区间覆盖 求染色段】
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: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on ...
- 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 这种情况 ...
随机推荐
- Linux gcc中的LIBRARY_PATH 和 LD_LIBRARY_PATH
1. GNU 上关于LIBRARY_PATH的说明: LIBRARY_PATH The value of LIBRARY_PATH is a colon-separated list of direc ...
- 11g Oracle Rac安装(基于linux6)可能出现的问题
11g Oracle Rac安装(基于linux6)可能出现的问题汇总: 7)使用"yum"命令执行节点的自动配置失败. 修改一下 /etc/resolv.conf,添加: nam ...
- linux的一页是多大
命令 getconf PAGESIZE 结果为4096,即一页=4096字节=4KB(注意是Byte,1B=8bit) 在使用mmap映射函数时,它的实际映射单位也是以页为单位的,即不过我们把MAP_ ...
- libTIFF 图像读取与保存
本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/YhL_Leo/article/details/49848391 1 头文件 libtif ...
- Majority Element:主元素
Given an array of size n, find the majority element. The majority element is the element that appear ...
- Android--Fragment与Activity通信
package com.example.testfragment; import com.example.testfragment.MainFargment.BackString; import an ...
- OpenGL编程逐步深入(九)插值处理
注:文中VS代指顶点着色器,FS代指片段着色器. 准备知识 这个教程和大家展示3d管道中非常重要的部分,即Interpolation(插值).光栅化程序执行的插值变量由VS产生.正如你已经见到过的,为 ...
- View的双击动作
有时在android中需要为某一控件设置双击监听,实现也挺简单,自己动手吧.编码永远不是问题,思路才是最重要. public class DoubleClickDemo extends Activit ...
- salt的grains
grains作用: 1.匹配 minion 2.收集信息 (每次重启minion才会收集) grains 数据存储在minion端. salt '*' grains.ls salt '*' grain ...
- iOS——集成支付宝 private key is NULL
问题描述:将生成的私钥,写进官方demo,还是一直报错:rsa_private read error : private key is NULL 解决方案:需要将RSA私钥转换成PKCS8格式