CS Course

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

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.

2≤n,q≤105

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

 
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
题意  求n个整数(除去) 二进制位运算 和 或 异或的结果
解析   求出前后缀询问时直接前缀后缀计算 
AC代码
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn= 1e5 + ;
const int inf = 0x3f3f3f3f;
typedef long long ll;
int n,m;
int sum1[maxn],sum2[maxn],sum3[maxn];
int rsum1[maxn],rsum2[maxn],rsum3[maxn];
int a[maxn];
int main(int argc, char const *argv[])
{
while(scanf("%d %d",&n,&m)==)
{
scanf("%d",&a[]);
sum1[]=sum2[]=sum3[]=a[];
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum1[i]=sum1[i-] & a[i];
sum2[i]=sum2[i-] | a[i];
sum3[i]=sum3[i-] ^ a[i];
}
rsum1[n]=rsum2[n]=rsum3[n]=a[n];
for(int i=n-;i>=;i--)
{
rsum1[i]=rsum1[i+] & a[i];
rsum2[i]=rsum2[i+] | a[i];
rsum3[i]=rsum3[i+] ^ a[i];
//cout<<rsum1[i]<<" "<<rsum2[i]<<" "<<rsum3[i]<<endl;
}
int q;
while(m--)
{
scanf("%d",&q);
if(q==)
printf("%d %d %d\n",rsum1[],rsum2[],rsum3[]);
else if(q == n)
printf("%d %d %d\n",sum1[n-],sum2[n-],sum3[n-]);
else
printf("%d %d %d\n",sum1[q-] & rsum1[q+],sum2[q-]|rsum2[q+],sum3[q-]^rsum3[q+]);
}
}
return ;
}

2017ICPC/广西邀请赛1005(水)HDU6186的更多相关文章

  1. 2017ICPC/广西邀请赛1001(水)HDU6181

    A Math Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  2. 2017 ICPC 广西邀请赛1005 CS Course

    CS Course Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  3. 2017ACM/ICPC广西邀请赛 1005 CS Course

    CS Course Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  4. 2017 ICPC 广西邀请赛1004 Covering

    Covering Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  5. 2017ACM/ICPC广西邀请赛-重现赛1005 CS course

    2017-08-31 16:19:30 writer:pprp 这道题快要卡死我了,队友已经告诉我思路了,但是做题速度很缓慢,很费力,想必是因为之前 的训练都是面向题解编程的缘故吧,以后不能这样了,另 ...

  6. HDU 4847 陕西邀请赛A(水)

    HDU 4847 Wow! Such Doge! pid=4847" style="">题目链接 题意:给定文本,求有几个doge,不区分大写和小写 思路:水题.直 ...

  7. 2017ACM/ICPC广西邀请赛-重现赛 1007.Duizi and Shunzi

    Problem Description Nike likes playing cards and makes a problem of it. Now give you n integers, ai( ...

  8. 2017ACM/ICPC广西邀请赛-重现赛 1010.Query on A Tree

    Problem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey A learne ...

  9. 2017ACM/ICPC广西邀请赛-重现赛 1004.Covering

    Problem Description Bob's school has a big playground, boys and girls always play games here after s ...

随机推荐

  1. windows 下共享内存使用方法示例

    windows下共享内存使用方法较 linux 而言微微复杂 示例实现的功能 有一个视频文件,一块内存区域 : 程序 A,将该视频写入该内存区域 : 程序 B,从该内存区域读取该视频 : 代码模块实现 ...

  2. 9.11 test

    题面.pdf T1:通过打表发现,从一个点出发只有距离为1,2,3,5,6,9,10,13,17的点才不能到达: 那么我们转移的时候只有距离在20以内才不一定能直接转移,那么我们离散化之后; 对于每一 ...

  3. js知识点记录

    1.for...in:用于遍历数组或对象的属性. for(var prop in obj){console.log(obj[prop])}; 该循环遍历对于对象属性是无序的,可能是因为obj本来就是无 ...

  4. Locust no-web 模式与参数详解

    读前参考:<性能测试工具Locust > 熟悉 Apache ab 工具的同学都知道,它是没有界面的,通过命令行执行. Locust 同样也提供的命令行运行,好处就是更节省客户端资源. 命 ...

  5. 冒烟测试与BVT测试

    冒烟测试,它和回归测试的性质一样--只是一个测试活动,并不是一个测试阶段.冒烟测试贯穿于测试的任何一个阶段,单元测试.集成测试.系统测试里都有冒烟测试. 冒烟测试和其他所有的测试活动的目的不一样,它不 ...

  6. Python学习_05_条件、循环

    条件 和其他语言类似,python中使用if...elif...else来形成分支,支持三目操作符 ?:,python中没有switch,但是缩进的特性让if...elif...else的结构同样便于 ...

  7. Spring之Bean的基本概念

     转自http://blog.csdn.net/chenssy/article/details/8222744 Spring其实就是一个大型的工厂,而Spring容器中的Bean就是该工厂的产品.对于 ...

  8. Robot Framework学习笔记(一)------环境搭建

    Robot Framework是一款python编写的功能自动化测试框架.具备良好的可扩展性,支持关键字驱动,可以同时测试多种类型的客户端或者接口,可以进行分布式测试执行. 所需环境 一.安装pyth ...

  9. TPYBoard V102:能跑Python的stm32开发板

    近来micropython语言做硬件编程很火,随之而来的就开始带动着支持micropython语言编程的开发板也开始火的发烫,今天小编就来和大家介绍一款很经典的micropython开发板-TPYBo ...

  10. TurnipBit-MicroPython开发板:跟孩子一起DIY跳动的心

    天是越来越热了,小心脏也是越跳越快啊,为了表达现在激动的心情,必须做个激动的心开始跳动.紧接着就开始带领大家做个激动的心. 首先说说要借助的平台,这次仅仅需要借助一块TurnipBit开发板. Tur ...