广西2017邀请赛 Problem E CS Course

问题 E: CS Course

时间限制: 2 Sec   内存限制: 512 MB

题目描述

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 ≤ p≤ 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




题目大意:
n个数  q次询问  每次询问第pi个数字  求除去询问的这个数外其他全部数字的and、or、xor

分析:
分别求出每个二进制位的有多少个0   然后判断去除询问的数字外剩下的每个二进制位的and、or、转为十进制
关于xor  最后在xor一遍这个数即可



AC代码:
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include
#include 
#include 
#include 
#define gcd(a,b) __gcd(a,b)
#define FIN freopen("input.txt","r",stdin)
#define FOUT    freopen("output.txt","w",stdout)
typedef long long LL;
const LL mod=1e9+7;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
using namespace std;
int a[1000005];
int count0[1000005];
int main (){
    int n,p;
    while (scanf ("%d%d",&n,&p)!=EOF){
        memset(a,0,sizeof(a));
        memset(count0,0,sizeof(count0));
        int ans3=0;
        int maxn=0;
        for (int i=0;i>=1;len++;
                if (maxn1&&count0[j]>=1;
            }
            printf ("%d %d %d\n",ans1,ans2,ans3^a[temp-1]);
        }
          
    }
    return 0;
} 


你可能感兴趣的:(广西2017邀请赛 Problem E CS Course)