# CS Course

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 542    Accepted Submission(s): 264

Problem Description Little A has come to college and majored in Computer and Science.

Today he has learned bit-operations in Algorithm Lessons, and he got a problem as homework.

Here is the problem:

You are giving n non-negative integers

a1,a2,,an, and some queries.

A query only contains a positive integer p, which means you

are asked to answer the result of bit-operations (and, or, xor) of all the integers except

ap.

Input There are no more than 15 test cases.

Each test case begins with two positive integers n and p

in a line, indicate the number of positive integers and the number of queries.

2n,q105

Then n non-negative integers

a1,a2,,an follows in a line,

0ai109 for each i in range[1,n].

After that there are q positive integers

p1,p2,,pqin q lines,

1pin for each i in range[1,q].

Output For each query p, output three non-negative integers indicates the result of bit-operations(and, or, xor) of all non-negative integers except

ap in a line.

Sample Input

3 3 1 1 1 1 2 3

Sample Output

1 1 0 1 1 0 1 1 0

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

const int maxn = 100005;
int data[maxn];
int nand[100];
//int nor [100];

int main(){
//printf("%d\n",1^2^7);
int n,p;
while(scanf("%d%d",&n,&p)!=EOF){
memset(data,0,sizeof(data));
memset(nand,0,sizeof(nand));

int nnn=0;
int AND,OR,XOR=0;
int i,j;

for(i=1;i<=n;i++){
scanf("%d",&data[i]);
XOR=XOR^data[i];
int flag = data[i];
int nowi=1;
while(flag){
nand[nowi++]+=(flag%2);
flag/=2;
}
nnn=max(nnn,nowi);

}

for(i=0;i<p;i++){
int q;
scanf("%d",&q);
int ans1= XOR^data[q];
int ans2=0,ans3=0;
int now2=data[q];
int fi=1;
int fj=nnn;
while(fj--){
if((nand[fi]-(now2%2))==n-1)
ans2+=pow(2,fi-1);
if((nand[fi]-(now2%2))>0)
ans3+=pow(2,fi-1);
fi++;
now2/=2;
}
printf("%d %d %d\n",ans2,ans3,ans1);
}
}
return 0;
}