# 2017广西邀请赛CS Course（&|^位运算模拟）

[提交][状态][讨论版]

## 题目描述

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.

## 输入

There are no more than 15 test cases.
Each test case begins with two positive integers n(2 ≤ n ≤ 105) and p(2 ≤ p ≤ 105) in a line, indicate the number of positive integers and the number of queries.
Then n non-negative integers a1,a2,...,an follows in a line, 0 ≤ ai ≤ 109 for each i in range [1,n].
After that there are q positive integers p1, p2, ...,pq in q lines, 1 ≤ pi ≤ n for each i in range [1,q].

## 输出

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.

## 样例输入

3 3
1 1 1
1
2
3


## 样例输出

1 1 0
1 1 0
1 1 0

【代码】：

#include <stdio.h>
#include <string.h>
#include <algorithm>
#define mset(a,i) memset(a,i,sizeof(a))
#define S1(n)     scanf("%d",&n)
#define S2(n,m)   scanf("%d%d",&n,&m)
using namespace std;
typedef long long ll;
const int MAX=1e6+5;
int a[MAX],b[MAX];
int n,m, And,Or,Xor;
int main()
{
while(~S2(n,m))
{
mset(b,0);
Xor=0,And=0xffffffff,Or=0;
for(int i=1;i<=n;i++)
{
int x;S1(x);
a[i]=x;
And&=x;
Or|=x;
Xor^=x;
for(int j=0;x;j++,x>>=1)
b[j]+=x%2;
}
while(m--)
{
int q;S1(q);q=a[q];
int A=And,O=Or,X=Xor;
X=X^q;
for(int j=0;j<=30;j++,q>>=1)
{
if(b[j]==n-1&&q%2==0)A+=(1<<j);
if(b[j]==1  &&q%2   )O-=(1<<j);
}
printf("%d %d %d\n",A,O,X);
}
}
}

#### 广西2017邀请赛 Problem E CS Course

2017-08-29 22:32:49

#### 广西2017邀请赛 E: CS Course &,|,^ 运算

2017-09-03 11:09:32

#### CS Course HDU - 6186

2017-10-24 20:16:43

#### 2017广西邀请赛／hdu6186 CS Course （维护前缀和后缀）

2017-09-01 12:42:23

#### HDU 6186 CS Course（线段树区间操作）

2017-09-05 14:48:41

#### hdu 6186 CS Course 2017ACM/ICPC广西邀请赛-重现赛

2017-09-03 23:43:38

#### 【2017广西邀请赛】hdu 6186 CS Course

2017-09-06 11:52:09

#### ICPC2017南宁邀请赛1005&&HDU6197 （模拟

2017-09-19 14:26:28

#### CS Course 位运算

2018-05-22 21:54:47

#### 斯坦福CS课程列表

2017-07-03 21:30:54