hdu 6186



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  a_1,a_2,\cdots ,a_n, 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  a_p.
 

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.

2 \leq n,q \leq 10^5

Then n non-negative integers  a_1,a_2,\cdots,a_n follows in a line,  0 \leq a_i \leq 10^9 for each i in range[1,n].

After that there are q positive integers  p_1,p_2,\cdots,p_qin q lines,  1 \leq p_i \leq n 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  a_p in a line.
 

Sample Input
  
  
3 3 1 1 1 1 2 3
 

Sample Output
  
  
1 1 0 1 1 0 1 1 0
 

Source
 

Recommend
liuyiding

题意:给出一些数,让我们计算一下这些数的与  或 异或  的值,有q次询问,每次给出一个m,问我们除去队列中的第m'个数,剩余的数的三个值分别是多少

思路:非常简单的思路,只需要分别维护给出数列的前缀和和后缀和就可以了

ac代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int a[100005];
int b[100005];
int b1[100005];
int c[100005];
int c1[100005];
int d[100005];
int d1[100005];
int main()
{
    int n,q;
    while(cin>>n>>q)
    {
        for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
        b[1]=c[1]=d[1]=a[1];
        for(int i=2;i<=n;i++)
        {
            b[i]=b[i-1]&a[i];
            c[i]=c[i-1]|a[i];
            d[i]=d[i-1]^a[i];
        }
        b1[n]=c1[n]=d1[n]=a[n];
        for(int i=n-1;i>=1;i--)
        {
            b1[i]=b1[i+1]&a[i];
            c1[i]=c1[i+1]|a[i];
            d1[i]=d1[i+1]^a[i];
        }
        while(q--)
        {
            int m;
            scanf("%d",&m);
            if(m==1)
            printf("%d %d %d\n",b1[m+1],c1[m+1],d1[m+1]);
            else if(m==n)
            printf("%d %d %d\n",b[m-1],c[m-1],d[m-1]);
            else
            printf("%d %d %d\n",b[m-1]&b1[m+1],c[m-1]|c1[m+1],d[m-1]^d1[m+1]);
        }
    }
    return 0;
}



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  a_1,a_2,\cdots ,a_n, 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  a_p.
 

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.

2 \leq n,q \leq 10^5

Then n non-negative integers  a_1,a_2,\cdots,a_n follows in a line,  0 \leq a_i \leq 10^9 for each i in range[1,n].

After that there are q positive integers  p_1,p_2,\cdots,p_qin q lines,  1 \leq p_i \leq n 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  a_p in a line.
 

Sample Input
   
   
3 3 1 1 1 1 2 3
 

Sample Output
   
   
1 1 0 1 1 0 1 1 0
 

Source
 

Recommend
liuyiding
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值