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.
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].
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.
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].
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