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 jdk 管理工具
官网:http://www.jenv.be/ 安装: Linux / OS X $ git clone https://github.com/gcuisinier/jenv.git ~/.jenv M ...
- [Apple开发者帐户帮助]五、管理标识符(2)启用应用服务
您可以在证书,标识符和配置文件中查看和启用App ID的服务.包含已修改的App ID的供应配置文件将变为无效.您需要重新生成使用该App ID的配置文件. 注意:要为应用程序完全配置服务,请在Xco ...
- idea导入ssm项目启动tomcat报错404
用idea写ssm项目,基于之前一直在用spring boot 对于idea如何运行ssm花费了一番功夫 启动Tom act一直在报404 我搜了网上各种解决办法都不行,花费一天多的时间解决不了 就 ...
- ROS-URDF-建立模型
前言:建立一个简单的urdf模型 详解请参看教程http://wiki.ros.org/urdf/Tutorials/Building%20a%20Visual%20Robot%20Model%20w ...
- 使用MALTAB标定实践记录
记录一下整个相机的标定矫正过程,希望能够帮助到刚学习标定的童鞋们- 首先下载matlab calibration toolbox,百度搜索第一条就是了(http://www.vision.caltec ...
- window.dialogArguments
弹出子窗口window.showModalDialog( url, window ); 然后在弹出的子窗口中: window.dialogArguments 即为父窗口window对象的引用.想搞什么 ...
- JavaScript alert()函数的使用方法
这里向大家简单介绍一下JavaScript alert()函数的使用,alert--弹出消息对话框,并且alert消息对话框通常用于一些对用户的提示信息. JavaScript alert()函数 a ...
- C#:使用FastReport打印带图片传参模板的实现方法
大家都知道,C#打印图片可以直接调用PrintDocument控件的PrintPage事件,通过画刷对image对象直接进行绘制.但是这种方法存在局限,例如如果打印的图片需要按纸张大小进行缩放的话,那 ...
- 06-联系人管理(xib应用)
ViewController.h文件中: @interface ViewController : UIViewController - (IBAction)add:(UIBarButtonItem * ...
- 【HTTP】长连接和短连接
1. HTTP协议与TCP/IP协议的关系 HTTP的长连接和短连接本质上是TCP长连接和短连接.HTTP属于应用层协议,在传输层使用TCP协议,在网络层使用IP协议.IP协议主要解决网络路由和寻址问 ...