题目链接:https://cn.vjudge.net/contest/285962#problem/G

题目大意:给你n和m,n代表有n个数,然后让你找出一个最长的区间,使得这个区间内的所有的数的‘’或‘’都小于等于m。

具体思路:曲尺,两个指针来回弄就行,具体的细节在代码里面,(以前做过的题现在竟然做不出来了,,我)

AC代码:

 #include<iostream>
#include<stack>
#include<stdio.h>
#include<cmath>
#include<algorithm>
using namespace std;
# define ll long long
const int maxn = 3e6+;
ll a[maxn];
int main(){
freopen("wifi.in","r",stdin);
int T;
scanf("%d",&T);
while(T--){
ll n,m,tmp=,tot=,flag=,ans=,l,r;
scanf("%lld %lld",&n,&m);
for(ll i=;i<=n;i++){
scanf("%lld",&a[i]);
ans=max(ans,tot);
if(a[i]<=m&&!flag){
l=i;
r=i;
tot=;
tmp=a[i];
ans=max(ans,tot);
flag=;
}
else if(flag){
ans=max(ans,tot);
if((tmp|a[i])<=m){
r++;
tmp|=a[i];
tot++;//计数的时候是按照合法的来记的,不能通过r-l+1来判断
ans=max(ans,tot);
continue;
}
ans=max(ans,tot);
if(a[i]>m){
tot=;
flag=;
tmp=;
continue;
}
ans=max(ans,tot);
tmp=;//注意这里的tmp直接归零就可以了。
ll pos=l;
r++;//注意先r++.
for(ll j=r;j>=pos;j--){
if((tmp|a[j])<=m){
tmp|=a[j];
l=j;
}
else break;
}
tot=r-l+;// 合法块的大小重新赋值。
ans=max(ans,tot);
}
}
printf("%lld\n",ans);
}
return ;
}

G - WiFi Password Gym - 101608G (异或思维题+曲尺)的更多相关文章

  1. Gym 102028C - Supreme Command - [思维题][2018-2019 ACM-ICPC Asia Jiaozuo Regional Contest Problem C]

    题目链接:https://codeforces.com/gym/102028/problem/C Lewis likes playing chess. Now he has n rooks on th ...

  2. Gym 101775C - Traffic Light - [思维题]

    题目链接:http://codeforces.com/gym/101775/problem/C 题意: 给出 $N$ 个红绿灯,又给出 $N+1$ 个距离 $S_i = S_0,S_1, \cdots ...

  3. Gym 100801E Easy Arithmetic (思维题)

    题目:传送门.(需要下载PDF) 题意:给定一个长度不超过1000的字符串表达式,向该表达式中加入'+'或'-',使得表达式的值最大,输出该表达式. 题解:比如300-456就改成300-4+56,遇 ...

  4. A - Arcade Game Gym - 100814A (概率思维题)

    题目链接:https://cn.vjudge.net/contest/285964#problem/A 题目大意:每一次给你你一个数,然后对于每一次操作,可以将当前的数的每一位互换,如果互换后的数小于 ...

  5. UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)

    UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There W ...

  6. 思维题 Gym 100553A Alter Board

    题目传送门 /* 题意:一个n×m的矩形,相邻的颜色不同,黑或白.问最少的翻转次数,每次翻转可指定任意一个子矩形 思维题:最少要把偶数行和列翻转,也就是n/2+m/2次 */ #include < ...

  7. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  8. [UVA12235] Help Bubu 思维题+状态定义+Dp

    Online Judge:UVA12235 Label:思维题,状态定义,状压Dp 题面: 题目描述 有一个书架,上面放了n本书,从左往右的第i本书的高度为h[i].定义书架的混乱度为连续等高段的个数 ...

  9. ACM思维题训练 Section A

    题目地址: 选题为入门的Codeforce div2/div1的C题和D题. 题解: A:CF思维联系–CodeForces -214C (拓扑排序+思维+贪心) B:CF–思维练习-- CodeFo ...

随机推荐

  1. C connect实现Timeout效果(Linux)

    C connect函数是阻塞的,现要实现非阻塞式的connect. int SocketClient::connectTimeOut(const int &connect_fd, const ...

  2. centos6.7不联网的情况下安装配置本地yum源

    1  cd / 2 mkdir -p /app/ios 3  cd /opt     mkdir ios 4   把下载好的centos-6.7-x86_64-bin-dvd1.iso  上传到 /o ...

  3. bzoj4326 树链剖分 + 线段树 // 二分 lca + 树上差分

    https://www.lydsy.com/JudgeOnline/problem.php?id=4326 题意:N个点的树上给M条树链,问去掉一条边的权值之后所有树链长度和的最大值最小是多少. 首先 ...

  4. Hadoop记录-日常运维操作

    1.Active NameNode hang死,未自动切换 #登录当前hang死 Active namenode主机,停止Namenode,触发自动切换.hadoop-daemon.sh stop n ...

  5. sql关联更新

    /****** Script for SelectTopNRows command from SSMS ******/SELECT * FROM [LFBMP.Operating].[dbo].[Sh ...

  6. Spring Boot 启动:No active profile set, falling back to default profiles: default

    启动 Spring Boot 失败,但是没有出现多余的异常信息: 检查之后发现是依赖的问题(之前依赖的是 spring-boot-starter),修改即可: 方法二: pom.xml加上下面两个依赖 ...

  7. bzoj千题计划312:bzoj2119: 股市的预测(后缀数组+st表)

    https://www.lydsy.com/JudgeOnline/problem.php?id=2119 题意:将给定数组差分后,求ABA形式的字串个数,要求|B|=m,|A|>0 1.后缀数 ...

  8. 2016vijos 1-2 股神小L(堆)

    维护前i天的最优解,那么在后面可能会对前面几天的买卖情况进行调整 如果前面买入,买入的这个在后面一定不会卖出 如果前面卖出,卖出的这个可能会在后面变成买入,因为买这个,卖后面的会获得更多的收益 用一个 ...

  9. JVM垃圾回收机制与内存回收

    暂时转于:https://blog.csdn.net/qq_27035123/article/details/72857739 垃圾回收机制 GC是垃圾回收机制,java中将内存管理交给垃圾回收机制, ...

  10. JS 样式字符串 转 JSON对象

    项目中需要把div 上的样式值转成数据展示 形如: padding: 7px 2px 1px 3px; color: rgb(238, 65, 65); background-color: rgb(2 ...