感觉这个思路非常巧妙啊~

code:

#include <bits/stdc++.h>
#define ll long long
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
ll qpow[40];
int main()
{
// setIO("input");
ll a=0,b=0,re=0;
int i,j,n,m;
scanf("%d%d",&n,&m);
for(i=0;i<40;++i) qpow[i]=1ll<<i, a+=qpow[i];
for(i=1;i<=n;++i)
{
ll x;
char op[5];
scanf("%s%lld",op,&x);
if(op[0]=='A') a&=x,b&=x;
if(op[0]=='O') a|=x,b|=x;
if(op[0]=='X') a^=x,b^=x;
}
for(i=33;i>=0;--i)
{
if(b&qpow[i]) re+=qpow[i];
else if(a&qpow[i] && qpow[i]<=1ll*m) re+=qpow[i], m-=(int)qpow[i];
}
printf("%lld\n",re);
return 0;
}

  

线段树版(可以改装改装加个单点修改之类的)

code:

#include <bits/stdc++.h>
#define N 100005
#define lson now<<1
#define rson now<<1|1
#define ll unsigned long long
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
int n,m;
struct node
{
ll f0,f1;
node operator+(const node &b)const
{
node a;
a.f0=(~f0&b.f0)|(f0&b.f1);
a.f1=(~f1&b.f0)|(f1&b.f1);
return a;
}
}f[N<<2],A[N];
void build(int l,int r,int now)
{
if(l==r)
{
f[now]=A[l];
return;
}
int mid=(l+r)>>1;
if(l<=mid) build(l,mid,lson);
if(r>mid) build(mid+1,r,rson);
f[now]=f[lson];
if(rson) f[now]=f[now]+f[rson];
}
int main()
{
// setIO("input");
int i,j;
scanf("%d%d",&n,&m);
for(i=1;i<=n;++i)
{
ll x;
char op[5];
scanf("%s%llu",op,&x);
if(op[0]=='A') A[i]=(node){0,x};
if(op[0]=='O') A[i]=(node){x,~0};
if(op[0]=='X') A[i]=(node){x,~x};
}
build(1,n,1);
ll re=0;
for(i=32;i>=0;--i)
{
if(f[1].f0&(1ll<<i)) re+=(1ll<<i);
else if((f[1].f1&(1ll<<i)) && (1ll<<i)<=1ll*m)
{
m-=(int)(1ll<<i);
re+=(1ll<<i);
}
}
printf("%lld\n",(long long)re);
return 0;
}

  

最新文章

  1. KendoUI系列:DatePicker
  2. git中使用.gitignore文件
  3. java 将长度很长的字符串(巨大字符串超过4000字节)插入oracle的clob字段时会报错的解决方案
  4. Dr.com校园网客户端故障解决方法
  5. 各大Oj平台介绍[转]
  6. linux下mysql环境支持中文配置步骤
  7. Eclipse SDK构建J2EE开发环境
  8. 【Zookeeper】源码分析之持久化--FileSnap
  9. 【翻译】 Guice 动机——依赖注入的动机
  10. svg在vue-cli3中的配置
  11. Asp.Net WebAPI核心对象解析(三)
  12. 用python实现一个无界面的2048
  13. [Ubuntu] 如何设置静态 IP 和 DNS
  14. Ionic项目中如何使用Native Camera
  15. PHP常见的字符串方法
  16. 若p是与10互质的质数,则p-1个9能被p整除
  17. CentOS编译安装php7.2
  18. Web框架(Day64)
  19. Entity Framework Tutorial Basics(32):Enum Support
  20. 51nod1202【DP-树状数组维护】

热门文章

  1. diy操作系统 附录:gcc栈帧开启与关闭
  2. 【数据结构】洛谷2019 OI春令营 - 普及组 作业
  3. 3.ASP.NET Core Docker学习-构建单机多容器环境
  4. 【解决方法】You seem to have the current working directory in your LD_LIBRARY_PATH environment variable.
  5. python __enter__ 与 __exit__的作用,以及与 with 语句的关系(转)
  6. Warning: popen() has been disabled for security reasons in OS/Guess.php on line 241
  7. C# SHA512和Base64加解密方法
  8. (十四)角色管理(Ztree插件的基本使用)
  9. (九)SpringBoot之使用jsp
  10. (五)springmvc之获取表单提交的数据