HDU
来源:互联网 发布:红蜘蛛软件年费 编辑:程序博客网 时间:2024/05/24 00:25
题意:给定n 个数和 q 个查询, qi 为查询数,求去掉 下标为qi 的元素后其他元素 and , or , xor的结果
分析:对于xor 直接 ^ a[qi] 即可,其它则考虑a[qi] 二进制每一位为1或0的情况,当只有这个数当前位为1 的时候,or 结果去掉当前位,当只有这个数当前位为0的时候,and 加上当前位
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <map>using namespace std;typedef long long int ll;map<int,int>mp;#define maxn 100005int n , q;ll c[maxn];ll _and,_or,_xor;void deal(ll a){ int cnt = 0; while( a ) { int x = a%2 ; a/=2; if( x )mp[cnt]++; cnt++; }}void dealAnd(ll a){ for(int i = 0 ; i < 30 ; ++i) { if( mp[i] == n - 1 && (a & (1<<i)) == 0 ) { _and|=(1<<i); } }}void dealOr(int a){ for(int i = 0 ; i < 30 ; ++i) { if( mp[i] == 1 && (a & (1<<i)) ) { _or^=(1<<i); } }}int main(){ while( cin >> n >> q ) { mp.clear(); _and = _or = _xor = 0; for(int i = 1 ; i <= n ; ++i) { scanf("%lld",c+i); _xor ^= c[i]; _and &= c[i]; _or |= c[i]; if( i == 1 ) _and = _or = _xor = c[i]; deal(c[i]); } ll t1,t2,t3; t1 = _xor; t2 = _or; t3 = _and; for(int i = 0 ; i < q ; ++i) { int a; _xor = t1; _or = t2; _and = t3; scanf("%d",&a); if( n == 1 ) { printf("0 0 0\n"); continue; } _xor ^= c[a]; dealAnd(c[a]); dealOr(c[a]); cout << _and << " " << _or << " " << _xor << endl; } }}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- CentOS修改ulimit(最大进程数和最大文件打开数)
- android selector学习笔记
- 华为无线ap由fit升级到fat的方法
- 添加Entity Data时候,提示Entity Framework版本
- TF-IDF算法
- HDU
- qt tcp/ip协议简单的用户图书管理系统(若有错误,请提醒,谢谢)
- Docker 中 安装Linux镜像
- 折半查找
- c#代码规范
- 【Leetcode】33. Search in Rotated Sorted Array
- HashMap+ConcurrentHashMap+HashTable
- [[][[]]+[]][+[]][++[+[]][+[]]] is "n" in javascript
- 如何使用Burp Suite Macros绕过防护进行自动化fuzz测试