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 这种情况 ...
随机推荐
- matlab 中语句 a(b)的意思
a=[1 2; 3, 4; 5, 6]; b=[1 3 2 1; 1 2 4 2]; c=a(b) c = 1 5 3 1 1 3 ...
- Memcached存储溢出
Memcached存储溢出 测试数据生成程序: package com.stoon.test; public class TestFor { public static void main(Strin ...
- swift 给导航添加item,实现界面的跳转
//给导航添加item var rightItem = UIBarButtonItem(title: "First", style: UIBarButtonItem ...
- NUTCH2.3 hadoop2.7.1 hbase1.0.1.1 solr5.2.1部署(一)
Precondition: hadoop 2.7.1 Nutch 2.3 hbase 1.0.1.1 / hbase 0.98.13 solr 4.8.1 Linux version 3.16. ...
- 手机表单验证插件mvalidate的使用
使用 1.引入js和css <script type="text/javascript" src="../script/jquery-mvalidate.js&qu ...
- nginx 代理https后,应用redirect https变成http --转
原文地址:http://blog.sina.com.cn/s/blog_56d8ea900101hlhv.html 情况说明nginx配置https,tomcat正常http接受nginx转发.ngi ...
- 使用NiftyModeEffects对话框
最近看到一篇有关个性对话框的文章,里面介绍了非常酷的动画效果,开源的项目下载来试试,用法很简单. NoftyDialogEffects效果参考: http://tympanus.net/D ...
- 当fastJson邂逅大写字段时
在项目中遇到了一件令人头疼的事.使用fastJson反序列化时下面的Json时,得到对象属性总为null(如下图),可能细心的朋友一看就知道问题出在哪里,没错!问题就出在返回的字段首字母给大写了.fa ...
- cnmp安装失败,报错npm ERR! enoent ENOENT: no such file or directory,
1.cnmp安装失败 2.提示如下: bogon:node_modules liangjingming$ sudo npm install cnpm -g --registry=https://reg ...
- pcre 不支持 utf 的问题
问题: Error 500 preg_match(): Compilation failed: this version of PCRE is compiled without UTF suppor ...