拆分二进制
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
#define LL long long
LL n,m;
int to0[40],to1[40]; // 30
char s[30];
int main()
{
// freopen("a.in","r",stdin);
// freopen("wa.out","w",stdout);
scanf("%lld %lld",&n,&m);
for(int i=1;i<=30;i++) to1[i]=1;
for(int i=1;i<=n;i++)
{
LL tmp;
scanf("%s %lld",s+1,&tmp);
if(s[1]=='A')
{
for(int i=1;i<=30;i++)
{
int x=tmp%2;
tmp>>=1;
to0[i]=to0[i]&x;
to1[i]=to1[i]&x;
}
}
else if(s[1]=='O')
{
for(int i=1;i<=30;i++)
{
int x=tmp%2;
tmp>>=1;
to0[i]=to0[i]|x;
to1[i]=to1[i]|x;
}
}
else
{
for(int i=1;i<=30;i++)
{
int x=tmp%2;
tmp>>=1;
to0[i]=to0[i]^x;
to1[i]=to1[i]^x;
}
}
}
LL ans=0;
LL sum=0;
for(int i=30;i>=1;i--)
{
if(to1[i]>to0[i]&&(sum+(1ll<<(i-1)))<=m)
{
sum+=(1ll<<(i-1));
ans<<=1;
ans^=to1[i];
}
else
{
ans<<=1;
ans^=to0[i];
}
}
printf("%lld\n",ans);
return 0;
}