0可以表示任何1到m的数,求一个最长的连续上升序列长度

因为m的范围在10w,所以以每个节点为起点 进行二分,复杂度mlogm

思路:b[i]表示到 1 到 i 有几个数没有出现,二分的时候注意加等号

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<queue>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int maxn=+;
bool vis[maxn];
int b[maxn];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,m,sum=;
scanf("%d%d",&n,&m);
memset(vis,,sizeof(vis));
int x;
for(int i=; i<=n; ++i)
{
scanf("%d",&x);
if(!x)sum++;
else vis[x]=;
}
b[]=;
for(int i=; i<=m; ++i)
{
if(vis[i])b[i]=b[i-];
else b[i]=b[i-]+;
}
int ans=;
for(int i=; i<m; ++i)
{
int l=i,r=m,mid;
while(l<=r)
{
mid=(l+r)>>;
if(b[mid]-b[i-]>sum)r=mid-;
else l=mid+;
}
mid=(l+r)>>;
ans=max(ans,mid-i+);
}
printf("%d\n",ans);
}
return ;
}

FZU 2216 The Longest Straight 二分的更多相关文章

  1. FZU 2216——The Longest Straight——————【二分、枚举】

    Problem 2216 The Longest Straight Accept: 17    Submit: 39Time Limit: 1000 mSec    Memory Limit : 32 ...

  2. FZU 2216 The Longest Straight(最长直道)

    Description 题目描述 ZB is playing a card game where the goal is to make straights. Each card in the dec ...

  3. FZU 2216 The Longest Straight 模拟

    题目链接:The Longest Straight 就是一个模拟就是这样,T_T然而当时恶心的敲了好久,敲完就WA了,竟然有这么简单的方法,真是感动哭了.......xintengziji...zhi ...

  4. The Longest Straight(二分,离散化)

     Problem 2216 The Longest Straight Accept: 7    Submit: 14 Time Limit: 1000 mSec    Memory Limit : 3 ...

  5. FZU-2216 The Longest Straight(尺取法)

     Problem 2216 The Longest Straight Accept: 523    Submit: 1663Time Limit: 1000 mSec    Memory Limit ...

  6. The Longest Straight(FZUoj2216)

     Problem 2216 The Longest Straight Accept: 82    Submit: 203Time Limit: 1000 mSec    Memory Limit : ...

  7. 福建省赛--Problem E The Longest Straight(标记+二分)

    Problem E The Longest Straight Accept: 71    Submit: 293 Time Limit: 1000 mSec    Memory Limit : 327 ...

  8. FZU-2216 The Longest Straight (二分枚举)

    题目大意:给n个0~m之间的数,如果是0,那么0可以变为任意的一个1~m之间的一个数.从中选出若干个数,使构成一个连续的序列.问能构成的最长序列的长度为多少? 题目分析:枚举连续序列的起点,二分枚举二 ...

  9. 第六届福建省大学生程序设计竞赛(FZU2213—FZU2221)

    from:piaocoder Common Tangents(两圆之间的公公切线) 题目链接: http://acm.fzu.edu.cn/problem.php?pid=2213 解题思路: 告诉你 ...

随机推荐

  1. struts2与velocity的整合有两种方式

    1.以struts2为主.struts2内置了对velocity的支持,只要在<result name="success"?type="velocity" ...

  2. CPU使用率

    CPU使用率 事故回放 当时的情况是那个样子的: 1,正值饭点,客户电话说系统慢,几乎无法完成订单调度,有时还显示内存不足.当时心里的第一个声音就是,服务器配置太低了,远程一看,2核4G内存,cpu平 ...

  3. 使用 Android Studio 跑新浪微博SDK Demo遇到的问题及解决

    概述 这是新浪微博官方 Android SDK Demo 使用 Android Studio 导入.编译并运行通过的版本. 源码:WeiboSdkDemo 官方项目请点击: weibo_android ...

  4. CQRS学习——最小单元的Cqrs(CommandEvent)[其一]

    [说明:博主采用边写边思考的方式完成这一系列的博客,所以代码以附件为准,文中代码仅为了说明.] 结构 在学习和实现CQRS的过程中,首要参考的项目是这个[http://www.cnblogs.com/ ...

  5. 【线段树/数学/扩展欧几里得】 Bzoj 3913:奇数国

    Description 在一片美丽的大陆上有100000个国家,记为1到100000.这里经济发达,有数不尽的账房,并且每个国家有一个银行.某大公司的领袖在这100000个银行开户时都存了3大洋,他惜 ...

  6. [转载]vs2012中使用Spring.NET报错:Spring.Context.Support.ContextRegistry 的类型初始值设定项引发异常

    学习使用Spring.NET中的时候,写了一个Demo,在运行时报了一个错误:Spring.Context.Support.ContextRegistry 的类型初始值设定项引发异常. 重新整理思绪, ...

  7. hdu 4726

    贪心 不是很难  各种细节注意 #include <cstdio> #include <cstring> #include <algorithm> using na ...

  8. ValueError: Attempted relative import in non-package

    执行:python deom/scripts/populate.py ValueError: Attempted relative import in non-package solve:python ...

  9. linux下mysql修改数据库账户root密码

    #先停止mysql,再运行下一句 $ mysqld_safe --user=mysql --skip-grant-tables --skip-networking & $ mysql -u r ...

  10. ZOJ 2563 Long Dominoes(状态压缩DP)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1563 题目大意:在h*w的矩阵里铺满1*3的小矩阵,共有多少种方法 ...