题干:

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,⋯,ana1,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 apap.

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

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

After that there are q positive integers p1,p2,⋯,pqp1,p2,⋯,pqin q lines, 1≤pi≤n1≤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 apap 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 个查询,qi 为查询数,求去掉下标为qi 的元素后其他元素 and , or , xor的结果。

解题报告:

这题也可以用线段树nlogn搞或者直接处理前缀后缀然后on搞(因为没有修改嘛)然后也可以按位统计然后nlogn乱搞。。

但是前者没法做带更新的,后者可以。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
int cnt[44];
ll a[MAX];
int n,q,p;
int main()
{while(~scanf("%d%d",&n,&q)) {memset(cnt,0,sizeof cnt);ll Xor = 0;for(int i = 1; i<=n; i++) scanf("%lld",a+i),Xor ^= a[i];for(int i = 1; i<=n; i++) {for(int j = 0; j<33; j++) {cnt[j] += (a[i]>>j)&1;}}while(q--) {scanf("%d",&p);ll And=0,Or=0,X;ll tar = a[p];X = Xor^tar;for(int j = 0; j<33; j++) {ll tmp = (tar>>j)&1;if(cnt[j]-tmp>0) Or |= (1<<j);if(cnt[j]-tmp == n-1) And |= (1<<j);}printf("%lld %lld %lld\n",And,Or,X);} }return 0 ;
}

AC代码2:

#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
#define mid ((st[id].l+st[id].r)>>1)
#define lson (id<<1)
#define rson ((id<<1)|1)using namespace std;const int N = 150000;
int arr[N];
struct Node{int l, r, OR, XOR, AND;
}st[N<<3];void build(int id, int l, int r)
{st[id].l = l; st[id].r = r;if(l == r){st[id].OR = arr[l];st[id].AND = arr[l];st[id].XOR = arr[l];return;}build(lson, l, mid);build(rson, mid+1, r);st[id].OR = st[lson].OR | st[rson].OR;st[id].XOR = st[lson].XOR ^ st[rson].XOR;st[id].AND = st[lson].AND & st[rson].AND;
}int query(int id, int l, int r, int op){if(st[id].l == l && st[id].r == r){if(op == 1)return st[id].OR;if(op == 2)return st[id].XOR;if(op == 3)return st[id].AND;}if(l > mid)return query(rson, l, r, op);else if(r <= mid)return query(lson, l, r, op);else{if(op == 1)return query(lson, l, mid, op) | query(rson, mid+1, r, op);if(op == 2)return query(lson, l, mid, op) ^ query(rson, mid+1, r, op);if(op == 3)return query(lson, l, mid, op) & query(rson, mid+1, r, op);}
}int main()
{int n, q;while(scanf("%d%d", &n, &q)!=EOF){for(int i = 1; i <= n; i++)scanf("%d", &arr[i]);build(1, 1, n);int p;while(q--){scanf("%d", &p);if(p == 1)printf("%d %d %d\n", query(1, 2, n, 3), query(1, 2, n, 1), query(1, 2, n, 2));else if(p == n)printf("%d %d %d\n", query(1, 1, n-1, 3), query(1, 1, n-1, 1), query(1, 1, n-1, 2));else    printf("%d %d %d\n", query(1, 1, p-1, 3)&query(1, p+1, n, 3), query(1, 1, p-1, 1)|query(1, p+1, n, 1), query(1, 1, p-1, 2)^query(1, p+1, n, 2));}}return 0;
}

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

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

  4. C语言按位与 按位或 按位异或 按位取反

    与运算:& 两者都为1为1,否则为0 1&1=1,  1&0=0,  0&1=0,  0&0=0 或运算:| 两者都为0为0,否则为1 1|1 = 1,  1| ...

  5. C语言按位与 按位或 按位异或 按位取反(二)

    位运算是指按二进制进行的运算.在系统软件中,常常需要处理二进制位的问题.C语言提供了6个位操作运算符.这些运算符只能用于整型操作数,即只能用于带符号或无符号的char,short,int与long类型 ...

  6. C语言按位与 按位或 按位异或 按位取反 (一)

    与运算:& 两者都为1为1,否则为0 1&1=1,  1&0=0,  0&1=0,  0&0=0 或运算:| 两者都为0为0,否则为1 1|1 = 1,  1| ...

  7. 【HDU 6411】带劲的and和 【并查集 + 二进制拆位】

    度度熊专门研究过"动态传递闭包问题",他有一万种让大家爆蛋的方法:但此刻,他只想出一道简简单单的题--至繁,归于至简 度度熊有一张n个点m条边的无向图,第i个点的点权为viviv_ ...

  8. CS Course HDU - 6186

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

  9. c/c++位操作简介--移位、位与、位或、异或

    概述 C/C++里面位操作符表示为如下:左移位 << ,右移位 >>,位与 &,位或 | ,位异或 ^,按位求反~. 位操作符针对的是补码形式(可参见下面的例子,其实我 ...

最新文章

  1. scanf函数详解与缓冲区
  2. UA OPTI512R 傅立叶光学导论22 透镜成像与傅立叶变换
  3. java整数的反转_反转Java中的整数
  4. C#程序集相关的概念
  5. 如何设置mysql字符集支持utf-8 和gbk_mysql建表的时候设置表里面的字段的字符集是utf-8要怎么设置?默认建好后我去mysql里看字符集都是gbk...
  6. Springboot2.x 拦截器
  7. java pingfang,PingFang sc字体的使用
  8. Topaz Sharpen AI 4 人工智能锐化
  9. FX3SA三菱PLC使用软件GX Works2编写程序(梯形图等)
  10. 软件项目管理第五章笔记---项目成本管理
  11. oppo手机显示服务器连接错误,OPPO手机连不上wifi怎么办?OPPO连不上wifi的四种解决方法...
  12. 为什么华为a1路由器网速变慢_华为路由器上网速度慢怎么办?
  13. 每时每刻做最有效的seo操作
  14. 摩羯座|摩羯座性格分析
  15. 真正的互联网诞生:TCP/IP协议的出现
  16. 交互方式的系统总结:如何让App拥有一个有趣的“灵魂”?
  17. calltransaction弹出新的窗口_SAP刘梦_新浪博客
  18. java-面向对象编程-三大特性之封装
  19. 【因式分解】x^n+1,当 n 为偶数,系数为实数域的因式分解
  20. 【开源云要闻回顾】RedHat将支持微软容器、ONAP与MEF达成合作......

热门文章

  1. 影院平台搭建 - (6)一个靠谱的视频播放方案的感想
  2. 浅析PetShop程序中的购物车和订单处理模块(Profile技术,异步MSMQ消息)
  3. [Leedcode][JAVA][第45题][跳跃游戏 II][贪心算法]
  4. [leedcode][JAVA][365][BFS]
  5. 1558. 得到目标数组的最少函数调用次数 二进制|思维
  6. Leetcode 1559二维网格图中探测环 技巧DFS|剪枝
  7. mysql一个表几亿数据_如何在mysql 造1亿条记录的大容量数据表?
  8. oracle 怎么创建类型,ORACLE—002:Create之创建类型
  9. ST7789V2 LCD驱动芯片
  10. 文档根元素 project 必须匹配 doctype 根 null_快评:全新MG5上市6.49万起,但买它必须准备10万?...