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 这种情况 ...
随机推荐
- ASP.NET-ajax.BeginForm使用02
Ajax.BeginForm中OnFailure.Onsuccess.OnComplete函数是可以处理从后台返回的数据的,比直接使用jquery的$.ajax方法还要节约时间 @using( ...
- COGS——T 1578. 次小生成树初级练习题
http://www.cogs.pro/cogs/problem/problem.php?pid=1578 ☆ 输入文件:mst2.in 输出文件:mst2.out 简单对比时间限制:1 ...
- Android开发学习之事件处理和Button具体解释
Android的事件处理机制: 1.基于监听器的事件处理 --- 组件绑定特定的事件监听器 --- 重点 2.基于回调的事件处理 --- 主要做法是重写Android组件特定的回调函数, ...
- Google笔试(2015年8月)
华电北风吹 天津大学认知计算与应用重点实验室 日期:2015/8/21 这三道题目的PDF能够在这里下载 https://github.com/ncepuzhengyi/jobHuntingExam/ ...
- groovy : poi 导出 Excel xlsx
參考 file:///poi-3.10-FINAL/docs/spreadsheet/how-to.html#sxssf text2xlsx.groovy 代码例如以下 package xlsx; i ...
- ormlite 中的onUpgrade
public class DBHelper extends OrmLiteSqliteOpenHelper { public static final String DB_NAME = "y ...
- XXXfragment that is not a fragment错误,fragment认不出来
要注意的是fragment事实上是有两个版本号的,一个是 import android.support.v4.app.Fragment; 另外一个是 import android.app.Fragme ...
- linux+apache+mysql+php平台构建及环境配置
1.我使用的centos6.安装时已经选择安装apach.mysql,事实上在运行下列两行命令的时候又对其进行了更新.所以说装的时候能够不安装,免得浪费时间. yum install php-mysq ...
- backtrack5实现局域网DNS欺骗
前言:不得不说Linux下的神器挺多,越来越喜欢Linux了.. . 測试环境 linux backtrack 5 windows xp 先在Linux下开 ...
- nyoj--49--开心的小明(背包)
开心的小明 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 小明今天很开心,家里购置的新房就要领钥匙了,新房里有一间他自己专用的很宽敞的房间.更让他高兴的是,妈妈昨天对他 ...