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 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 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 2≤n,q≤105

Then n non-negative integers  a1,a2,⋯,an a1,a2,⋯,an follows in a line,  0≤ai≤109 0≤ai≤109 for each i in range[1,n].

After that there are q positive integers  p1,p2,⋯,pq p1,p2,⋯,pqin q lines,  1≤pi≤n 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 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和q两组数,n代表n个数,q代表q次询问,每次询问是输入一个数m,然后输出三个数,分别是除了第m个数以外的所有数的按位与按位或按位异或,三个值;
思路:开六个数组,直接模拟前缀和后缀暴力即可:
#include <stdio.h>
long long a[100005];
long long s1[100005] , S1[100005];
long long s2[100005] , S2[100005];
long long s3[100005] , S3[100005];
int main() {long long n , q , m;while(~scanf("%lld%lld",&n,&q)) {for(int i = 1; i <= n; i++) {scanf("%lld",&a[i]);}s1[1] = a[1];s2[1] = a[1];s3[1] = a[1];for(int i = 2; i <= n; i++) {//前缀 s1[i] = s1[i-1]|a[i];s2[i] = s2[i-1]&a[i];s3[i] = s3[i-1]^a[i];}S1[n] = a[n];S2[n] = a[n];S3[n] = a[n];for(int i = n - 1; i >= 1; i--) {//后缀 S1[i] = S1[i+1]|a[i];S2[i] = S2[i+1]&a[i];S3[i] = S3[i+1]^a[i];}for(int i = 0; i < q; i++) {scanf("%lld",&m);if(m == 1) {printf("%lld %lld %lld\n",S2[m+1] , S1[m+1] , S3[m+1]);}else if(m == n) {printf("%lld %lld %lld\n",s2[m-1] , s1[m-1], s3[m-1]);}else {printf("%lld %lld %lld\n",s2[m-1]&S2[m+1] , s1[m-1]|S1[m+1] , s3[m-1]^S3[m+1]);}}}return 0;
}

CS Course HDU - 6186相关推荐

  1. HDU 6186 CS Course

    点击打开链接 CS Course Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. HDU - 6186 CS Course(维护前缀+后缀)

    题目链接:点击查看 题目大意:给出n个数以及m个查询,每个查询包括一个数字,要求输出除了该数字之外的位运算的"或和","与和"和"异或和" ...

  3. 【HDU - 6186】CS Course(按位与,按位或,按位异或的区间统计,二进制拆位)

    题干: Little A has come to college and majored in Computer and Science. Today he has learned bit-opera ...

  4. HDU 6186 2017广西邀请赛:CS Course

    题意: n个数,m次查询,每次给出一个p,求出除了第p个数以外其它所有数的且和,或和,异或和 统计下每个二进制位1的数量,例如z[5] = x表示有x个数第5个二进制位为1 之后每次查询只要check ...

  5. HDU 6186 CS Course(线段树区间操作)

    Little A has come to college and majored in Computer and Science. Today he has learned bit-operation ...

  6. 2017ACM/ICPC广西邀请赛

    2017ACM/ICPC广西邀请赛(感谢广西大学) 题号 题目 考点 难度 A A Math Problem 数论 签到题 B Color it C Counting Stars D Covering ...

  7. hdu 1174:爆头(计算几何,三维叉积求点到线的距离)

    爆头 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...

  8. poj 2096 , zoj 3329 , hdu 4035 —— 期望DP

    题目:http://poj.org/problem?id=2096 题目好长...意思就是每次出现 x 和 y,问期望几次 x 集齐 n 种,y 集齐 s 种: 所以设 f[i][j] 表示已经有几种 ...

  9. HDU 4685. Prince and Princess

    链接 http://acm.hdu.edu.cn/showproblem.php?pid=4685 题意 nnn 个王子,mmm 个公主,每个王子可以娶他喜欢的公主中的一个,每个公主只能嫁个一个王子, ...

最新文章

  1. extra加ing_英语词汇学各个章节的内容
  2. 4.6 什么是神经风格迁移-深度学习第四课《卷积神经网络》-Stanford吴恩达教授
  3. DFT实训教程笔记2(bibili版本)- Scan synthesis practice
  4. val_loss突然变很大_女朋友突然变得很冷淡是怎么回事?该怎么办
  5. kafka 丢弃数据_Kafka史上最详细原理总结下
  6. 云原生开发者须具备的1+N技能,开启第二曲线
  7. Linux内核 eBPF基础:BCC (BPF Compiler Collection)
  8. mysql skip slave_MYSQL replication slave-skip-errors 详解
  9. hadoop与mysql的区别_数据库与hadoop与分布式文件系统的区别和联系
  10. 7.数电复刻 之 门电路
  11. 设置eMMC和DDR的工作频率
  12. python怎么打开h5文件_h5文件python
  13. java实现中文数字与阿拉伯数字互相转换
  14. 什么是promise?
  15. 自己动手设计一个简单的HTML网页
  16. Windows11 校园网连ftp登录上传作业失败
  17. 1.2 储存卡牌信息———自制卡牌游戏之旅
  18. D. Rescue Nibel(cf) 区间覆盖 + 组合数学
  19. php artisan 出错,使用php artisan serve命令获取错误
  20. Windows11任务管理器

热门文章

  1. 腾讯 Robotics X 轮腿式机器人 Ollie 亮相 ICRA 2021,花滑空翻样样行
  2. Ubuntu 通过设置vga=nomodeset禁掉显示器的刷屏
  3. 这几款软件真的好用,快来一试
  4. 墨言教育摄影技能干货分享|优秀摄影作品欣赏——创意与思想
  5. 小工具———字符编码转换查看(MFC)
  6. IDEA怎么设置字体大小
  7. combox数据过滤 wpf_WPF combox数据绑定的问题
  8. zbrush工资高不高就看姿势好不好,几招入行的一定要学会
  9. 创意时尚美观 光电LED智能玻璃屏优势
  10. javascript实现 京东淘宝等商城的商品图片大图预览功能