思路:调了一个小时,但是发现自己线段树木有写错,颜色统计出了错误。但是不明白自己颜色统计为什么错了。
求大佬指点迷津。思路很简单,就是一个裸的线段树。只要推出样例就做出来了。
以下是两种颜色统计:
这是我的错误的:
for(int i=;i<=;i++){
if(vis[i]!=vis[i-]&&vis[i-]!=-) ans[vis[i-]]++;
if(i==&&vis[i]!=-) ans[vis[i-]]++;
}

后来大佬解决了疑惑,改成酱就对了:

for(int i=;i<=;i++)
if(vis[i]!=vis[i-]&&vis[i-]!=-) ans[vis[i-]]++;

是因为本来i就超过了最大范围,所以最后一个一定会被统计上,再加上特判就会造成重复计数。

这是正确的:

int i=;
while(i<MAXN){
int flagor=vis[i],j=i+;
if(flagor==-){ ++i;continue; }
while(vis[j]!=-&&vis[j]==flagor&&j<MAXN) ++j;
++ans[flagor];i=j;
}

cpp:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 8010
using namespace std;
int n,m;
struct nond{
int l,r,flag;
}tree[MAXN*];
int vis[MAXN*],ans[MAXN*];
void build(int now,int l,int r){
tree[now].l=l;tree[now].r=r;tree[now].flag=-;
if(tree[now].l==tree[now].r) return ;
int mid=(tree[now].l+tree[now].r)/;
build(now*,l,mid);
build(now*+,mid+,r);
}
void down(int now){
tree[now*].flag=tree[now].flag;
tree[now*+].flag=tree[now].flag;
tree[now].flag=-; return ;
}
void change(int now,int l,int r,int k){
if(tree[now].l==l&&tree[now].r==r){
tree[now].flag=k;
return ;
}
if(tree[now].flag==k) return ;
if(tree[now].flag!=-) down(now);
int mid=(tree[now].l+tree[now].r)/;
if(r<=mid) change(now*,l,r,k);
else if(l>mid) change(now*+,l,r,k);
else{ change(now*,l,mid,k);change(now*+,mid+,r,k); }
}
void query(int now){
if(tree[now].flag!=-){
for(int i=tree[now].l;i<=tree[now].r;i++)
vis[i]=tree[now].flag;
return ;
}
if(tree[now].l==tree[now].r) return ;
query(now*); query(now*+);
}
int main(){
while(scanf("%d",&n)!=EOF){
memset(ans,,sizeof(ans));
memset(vis,-,sizeof(vis));
build(,,);
for(int i=;i<=n;i++){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
change(,x+,y,z);
}
query();
for(int i=;i<=;i++)
if(vis[i]!=vis[i-]&&vis[i-]!=-) ans[vis[i-]]++;
for(int i=;i<=;i++)
if(ans[i]) printf("%d %d\n",i,ans[i]);
cout<<endl;
}
}

F - Count the Colors的更多相关文章

  1. F - Count the Colors(线段树)

    Painting some colored segments on a line, some previously painted segments may be covered by some th ...

  2. F - Count the Colors - zoj 1610(区间覆盖)

    有一块很长的画布,现在想在这块画布上画一些颜色,不过后面画的颜色会把前面画的颜色覆盖掉,现在想知道画完后这块画布的颜色分布,比如 1号颜色有几块,2号颜色有几块.... *************** ...

  3. F - Count the Colors ZOJ - 1610 线段树染色(染区间映射)

    题意:给一段0-8000的线段染色 问最后 颜色x 有几段 题解:标准线段树  但是没有push_up  最后查询是单点按顺序查询每一个点 考虑过使用区间来维护不同的线段有多少种各色的线段  思路是 ...

  4. (线段树) Count the Colors --ZOJ --1610

    链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82832#problem/F http://acm.zju.edu.cn/onli ...

  5. zoj 1610 Count the Colors 线段树区间更新/暴力

    Count the Colors Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...

  6. Count the Colors(线段树染色)

    Count the Colors Time Limit:2000MS    Memory Limit:65536KB    64bit IO Format:%lld & %llu Submit ...

  7. zoj 1610 Count the Colors

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=610  Count the Colors Time Limit:2000MS   ...

  8. Count the Colors(线段树,找颜色段条数)

    Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on ...

  9. Count the Colors

    Count the Colors Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Subm ...

随机推荐

  1. DNS隐蔽通道 是可以通过dig 子域名来追踪其真实IP的

    比如a.friendskaka.com 是我的外发子域名,那么可以按照下面两个命令来追踪IP: bonelee@bonelee-VirtualBox:~/桌面$ dig auth.a.friendsk ...

  2. poj--3061--Subsequence(贪心)

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10882   Accepted: 4498 Desc ...

  3. VBA 字符串处理函数集

    转自:http://blog.csdn.net/jyh_jack/article/details/2315345 mid(字符串,从第几个开始,长度)  在[字符串]中[从第几个开始]取出[长度个字符 ...

  4. Docker从安装部署到Hello World

    Docker 是 PaaS 提供商 dotCloud 开源的一个基于 LXC 的高级容器引擎,源代码托管在 Github 上, 基于go语言并遵从Apache2.0协议开源.Docker 是一个开源的 ...

  5. My97DatePicker 动态设置有效/无效日期

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  6. Android之通过配置Flavor实现一个项目打包成多个apk

    最近我老大问我一个问题,说Android可不可以像iOS那样,通过target对项目进行管理啊.老大提这个问题也是正常的,我公司的主要是帮别的公司做硬件定制的,每定制一个硬件就要定制一个APP,但是很 ...

  7. 【sqli-labs】 less2 GET - Error based - Intiger based (基于错误的GET整型注入)

    与less1相同,直接走流程 提交参数,直接order by http://localhost/sqli/Less-2/?id=1 order by 1%23 http://localhost/sql ...

  8. C#异步Async、Task、Await

    参考http://www.cnblogs.com/jesse2013/p/async-and-await.html 事例: static void Main(string[] args) { ; i ...

  9. 记录:通过SSH远程连接Ubuntu

    一.安装openssh服务器 $ sudo apt-get install openssh-server 二.启动ssh服务 安装完成后,启动服务: $ sudo /etc/init.d/ssh st ...

  10. html第八节课

    导航 1.首先在<head>里面引用一个JQUERY的文件以用来制作鼠标点击动画效果(从网站上下载即可) 1 <script language="javascript&qu ...