题目链接: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 sockets Errno

    在Windows下进行网络编程,免不了出现各种错误.在Linux下可以使用errno查看错误,但是根据stackoverflow上说,windows下应该使用: FormatMessage() WSA ...

  2. 苹果电脑自带python安装tensorflow一直有问题

    对于有些程序是不支持python3而支持python2的,为了在苹果电脑安装tensorflow, 首先sudo su到管理员权限 export TF_BINARY_URL=https://stora ...

  3. Linux 上 nginx配置

    1:安装工具包 wget.vim和gcc yum install -y wget yum install -y vim-enhanced yum install -y make cmake gcc g ...

  4. 一个关于finally和return的面试题

    public class Test{ public int add(int a,int b){ try { return a+b; } catch (Exception e) { System.out ...

  5. 【优秀的设计绘图软件】Affinity Designer Beta for Mac 1.7

        [简介] Affinity Designer 1.7 beta 中文版本,具有全新的UI界面和功能,支持最新的 macOS Mojave 10.14 系统,Affinity Designer是 ...

  6. vue init 解决办法

    /由于windows系统的某方面问题,vue脚手架安装可能会出现第一证书丢失 // 报错:vue-cli · Failed to download repo vuejs-templates/webpa ...

  7. Maven Tomcat7+ 实现自动化部署

    首先在Tomcat里配置deploy的用户(tomcat根目录/conf/tomcat-users.xml): <role rolename="tomcat"/> &l ...

  8. 【JQ】jq动态绑定事件.on()、解绑事件off()

    #JQ 绑定与解绑事件的方法的历史演变 1. jquery1.4 及之前的版本,由.click() 或 .bind()方法绑定的事件,不能适用脚本创建的新元素:即是说页面加载完成后,再动态创建的DOM ...

  9. js截取url地址后面的文件名

    let url = response.data.stuXscg[0].fj let num = url.lastIndexOf('/')+1 let name = url.substring(num) ...

  10. MVC 5 Scaffolder + EntityFramework+UnitOfWork Pattern 代码生成工具

    MVC 5 Scaffolder + EntityFramework+UnitOfWork Pattern 代码生成工具集成Visual Studio 2013 MVC 5 Scaffolder + ...