F - Count the Colors
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的更多相关文章
- F - Count the Colors(线段树)
Painting some colored segments on a line, some previously painted segments may be covered by some th ...
- F - Count the Colors - zoj 1610(区间覆盖)
有一块很长的画布,现在想在这块画布上画一些颜色,不过后面画的颜色会把前面画的颜色覆盖掉,现在想知道画完后这块画布的颜色分布,比如 1号颜色有几块,2号颜色有几块.... *************** ...
- F - Count the Colors ZOJ - 1610 线段树染色(染区间映射)
题意:给一段0-8000的线段染色 问最后 颜色x 有几段 题解:标准线段树 但是没有push_up 最后查询是单点按顺序查询每一个点 考虑过使用区间来维护不同的线段有多少种各色的线段 思路是 ...
- (线段树) 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 ...
- 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 ...
随机推荐
- 杂项-Java:自定义标签
ylbtech-杂项-Java:自定义标签 1.返回顶部 1. 一般我们说自定义标签是指JSP自定义标签.自定义标签在功能上逻辑上与javaBean 类似,都封装Java 代码.自定义标签是可重用的组 ...
- 【NOI1999、LOJ#10019】生日蛋糕(搜索、最优化剪枝、可行性剪枝)
主要是剪枝的问题,见代码,讲的很详细 #include<iostream> #include<cstdio> #include<cmath> #include< ...
- WPF播放器
最近由于工作需要,需要做一个播放软件,在网上参考了很多例子,园子里有很多代码.其中最多的就是wpf自带的MediaElement控件,或者VLC视频播放器. 先附我自己查询资料的链接: MediaEm ...
- 最简单的多线程死锁案例代码(Java语言)
package com.thread.test; public class DeadLock { private static Object firstMonitor = new Object(); ...
- js-var变量作用域
看代码: var a=10; function fn1(){ alert(a); var a=20; alert(a); } 运行结果:undefined 和 20 注意: 在函数内,变量如没用var ...
- dubbo之多版本
当一个接口实现,出现不兼容升级时,可以用版本号过渡,版本号不同的服务相互间不引用. 可以按照以下的步骤进行版本迁移: 在低压力时间段,先升级一半提供者为新版本 再将所有消费者升级为新版本 然后将剩下的 ...
- Percona Xtrabackup导出/导入单表
默认情况下,InnoDB表不能通过直接复制表文件的方式在mysql服务器之间进行移植,即便使用了innodb_file_per_table选项.而使用Xtrabackup工具可以实现此种功能,不过,此 ...
- 【Hexo】本地local4000打不开解决方法
错误:Cannot GET /spadesq.github.io/ (注:spadesq.github.io是原来放hexo文件夹的名字) 由于我后来把hexo文件夹搬迁到别处,但我发现打开本地,地址 ...
- mac nwjs入门
NW.js由node-webkit项目发展而来其实很多东西官网上都有.但是鉴于搜索引擎(百度,google)搜索到的相关文章,让人看的很不明白.所以决定写下此篇文章. 官网:https://nwjs. ...
- springMvc学习地址新
http://www.admin10000.com/document/6436.html 一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要的jar ...