Zju1610 Count the Colors
题面:
画一些颜色段在一行上,一些较早的颜色就会被后来的颜色覆盖了。
你的任务就是要数出你随后能看到的不同颜色的段的数目。
Input:
每组测试数据第一行只有一个整数n, 1 <= n <= 8000,等于填色的次数
接下来的n行每行有三个非负整数,他们之间用一个空格分开。
x1 x2 c
x1和x2表示填色段最左边的点和最右边的点, c表示填进的颜色。
所有数字都是在[0..8000]这个范围里的整数。
输入有多组测试数据,最后以文件结束符为结束。
Output:
输出的每一行都是最后能看到的颜色的数字,还有这种颜色的段数。
如果这种颜色最后不能见到,就不要打印出来。
每组数据后面跟一个空行。
Solution:
说实话,这道题十分的傻逼,我一开始想的时候一直没想出来,一看题解,豁然开朗:原来还可以这么暴力啊。。。
线段树,tree数组记录当前区间是否颜色一致,若颜色一致,则等于那个颜色,否则等于-1
那么叶子节点的tree记录的显然是自己的颜色,所以最后再线段树查找单点颜色就行了
把颜色都记录下来后,O(N)扫一遍就行了
Code:
#include<bits/stdc++.h>
#define N 8001
#define ls (q<<1)
#define rs (q<<1|1)
using namespace std;
int n,cl,cc,tree[N*5],col[N],ans[N];
inline int read(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
void pushdown(int q){
if(tree[q]!=-1)tree[ls]=tree[rs]=tree[q];
tree[q]=-1;
}
void change(int l,int r,int q,int L,int R,int v){
if(tree[q]==v)return ;
if(l>=L&&r<=R){
tree[q]=v;
return ;
}
pushdown(q);
int mid=(l+r)>>1;
if(mid>=L)change(l,mid,ls,L,R,v);
if(mid<R)change(mid+1,r,rs,L,R,v);
}
int query(int l,int r,int q,int x){
if(l==r)return tree[q];
int mid=(l+r)>>1;
pushdown(q);
if(mid>=x)return query(l,mid,ls,x);
if(mid<x)return query(mid+1,r,rs,x);
}
int main(){
while((scanf("%d",&n))!=EOF){
memset(tree,255,sizeof(tree));
memset(col,255,sizeof(col));
memset(ans,0,sizeof(ans));
for(int i=1;i<=n;i++){
int l=read(),r=read(),v=read();
change(0,N,1,l,r-1,v);//因为是区间长度,所以r要减一
}
int pre=-1;
for(int i=0;i<=N;i++){
int now=query(0,N,1,i);
if(now!=-1&&now!=pre)ans[now]++;
pre=now;
}
for(int i=0;i<=N;i++)
if(ans[i])printf("%d %d\n",i,ans[i]);
puts("");
}
return 0;
}
Zju1610 Count the Colors的更多相关文章
- Zju1610 Count the Colors(lazy标记详解)
Description 画一些颜色段在一行上,一些较早的颜色就会被后来的颜色覆盖了. 你的任务就是要数出你随后能看到的不同颜色的段的数目. Input 每组测试数据第一行只有一个整数n, 1 < ...
- Count the Colors(线段树染色)
Count the Colors Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit ...
- zoj 1610 Count the Colors
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=610 Count the Colors Time Limit:2000MS ...
- Count the Colors(线段树,找颜色段条数)
Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on ...
- Count the Colors
Count the Colors Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Subm ...
- (线段树) 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——————【线段树区间替换、求不同颜色区间段数】
Count the Colors Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Subm ...
- ZOJ 1610 Count the Colors【题意+线段树区间更新&&单点查询】
任意门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Count the Colors Time Limit: 2 ...
随机推荐
- SecureCRT 用法总结
SecureCRT 用法总结 1.下载与破解方法: Mac:https://www.jianshu.com/p/9427f12b1fdb Window:https://drive.google.c ...
- **测试某系统切换成docker部署之后性能的下降情况**
###分析 * 对比:某系统/docker* A:某系统性能情况* B:dockers部署的性能情况* 求出A&B两者之间的差异* 确定性能指标(tps)* 测试报告里体现:tps的变化 ## ...
- tomcat 在liunx中shutdown后进程仍然存在的两种实用解决办法
方法一: 查找tomcat进程并kill ps -elf | grep ${ctompath} | grep -v grep | awk '{print $4}' | xargs kill -9 此处 ...
- 廖雪峰git教程学习笔记
对git来说,没有消息就是最好的消息 使用 git init 把当前目录变为git仓库 要在仓库里加入文件,先在仓库目录新建这个文件后,比如新建一个文件xiaobai.txt,内容为: 在命令行里输入 ...
- Tree - AdaBoost with sklearn source code
In the previous post we addressed some issue of decision tree, including instability, lack of smooth ...
- 多tomcat 同一个浏览器 多个项目 会导致session覆盖
1,多tomcat 同一个浏览器 同一个项目 会导致session覆盖 个人猜测:一个服务器中有多个Tomcat服务器多个项目,每个服务器占用不同的端口号,当在同一个浏览器里面同时打开2个系统时,一个 ...
- traceroute命令详解
基础命令学习目录首页 原文链接:https://www.cnblogs.com/peida/archive/2013/03/07/2947326.html 通过traceroute我们可以知道信息从你 ...
- PSP总结
一.回顾1 (1)回想一下你曾经对计算机专业的畅想 当初你是如何做出选择计算机专业的决定的?经过一个学期,你的看法改变了么,为什么? 以前的回答:当初之所以选择计算机专业,是因为我比较喜欢数学,觉得计 ...
- Final发布用户使用报告 -- Thunder团队
Thunder爱阅app Final发布用户使用报告 用户数量:14人 以下为用户评论:(注:为了保护用户的姓名权,以下用户名以昵称形式给出.) 序列 昵称 个人信息 获得软件途径 使用次数 用户评论 ...
- Daily Scrum (2015/11/8)
由于编译大作业临近deadline以及各项选修课即将结课,虽然PM强调软工任务也很紧迫,但是大多数成员表示今天想请假一天.符美潇今天把自己所负责的数据库编码部分和谢金洛的UI进行了对接.在测试过程中发 ...