rt,用的是位运算,但是全TLE,目前确定问题出在 check 和 check1。
#include<bits/stdc++.h>
#define int long long
#define R read()
using namespace std;
int read()
{
int x=0,f=1;
char c=getchar();
while(c>'9'||c<'0')
{
if(c=='-')
{
f=-1;
}
c=getchar();
}
while(c>='0'&&c<='9')
{
x=(x<<1)+(x<<3)+c-48;
c=getchar();
}
return x*f;
}
void write(int x)
{
static int st[35],top=0;
if(x<0)
{
x=-x;
putchar('-');
}
do
{
st[top++]=x%10;
x/=10;
}while(x);
while(top)
{
putchar(st[--top]+48);
}
putchar(' ');
}
int a,b,c,d,n,m,U=63;
int check(int x)
{
for(int i=0ll;i<=U;i++)
{
if((x&(1ll<<i)))
{
write(i);
}
}
}
int check1(int x)
{
for(int i=0ll;i<=U;i++)
{
if(!(x&(1ll<<i)))
{
write(i);
}
}
}
signed main()
{
n=R;
char x;
if(n==0)
{
x=getchar();
}
for(int i=1,x;i<=n;i++)
{
x=R;
a+=(1ll<<x);
}
m=R;
if(m==0)
{
x=getchar();
}
for(int i=1,x;i<=m;i++)
{
x=R;
b+=(1ll<<x);
}
cout<<__builtin_popcountll(a)<<'\n';
c=(a&b);
d=(a|b);
check(c);
cout<<'\n';
check(d);
cout<<'\n';
check1(a);
cout<<'\n';
cout<<(a==b)<<endl;
cout<<((a&b)==a)<<endl;
cout<<(a%2)<<endl;
return 0;
}