HDU 6186 CS Course【前后缀位运算枚举/线段树】
【前后缀枚举】
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define debug() puts("++++")
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a,b,sizeof(a))
#define be begin()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
#define all 1,n,1
#define mod 998244353
#define pi acos(-1.0)
#define rep(i,x,n) for(int i=(x); i<(n); i++)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
const int INF = 1<<30;
const int maxn = 150000+3;
const double eps = 1e-8;
const int dx[] = {-1,1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
int dir[2]={-1,1};
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int t,n,m,d;
int a[maxn];
//& | ^
int px[maxn],py[maxn],pz[maxn];
int sx[maxn],sy[maxn],sz[maxn];
int main()
{
while(~scanf("%d%d",&n,&m))
{
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
px[1]=py[1]=pz[1]=a[1];
for(int i=2;i<=n;i++)
{
px[i]=px[i-1]&a[i];
py[i]=py[i-1]|a[i];
pz[i]=pz[i-1]^a[i];
}
sx[n]=sy[n]=sz[n]=a[n];
for(int i=n-1;i>=1;i--)
{
sx[i]=sx[i+1]&a[i];
sy[i]=sy[i+1]|a[i];
sz[i]=sz[i+1]^a[i];
}
while(m--)
{
scanf("%d",&d);
if(d==1)
printf("%d %d %d\n",sx[2],sy[2],sz[2]);
else if(d==n)
printf("%d %d %d\n",px[n-1],py[n-1],pz[n-1]);
else printf("%d %d %d\n",px[d-1]&sx[d+1],py[d-1]|sy[d+1],pz[d-1]^sz[d+1]);
}
}
}
/*
【题意】去掉给你的一个数d后的其他数的&、|、^
【类型】前缀+后缀去掉枚举的那个数,注意边界
【分析】女生赛有道去掉一个数求剩下数的GCD(换汤不换药
【时间复杂度&&优化】O(n)
【trick】
【数据】
*/
HDU 6186 CS Course【前后缀位运算枚举/线段树】的更多相关文章
- ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】
FZU 2105 Digits Count Time Limit:10000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- 枚举进行位运算 枚举组合z
枚举进行位运算--枚举组合 public enum MyEnum { MyEnum1 = , //0x1 MyEnum2 = << , //0x2 MyEnum3 = << , ...
- [BJWC2018]Border 的四种求法(后缀自动机+链分治+线段树合并)
题目描述 给一个小写字母字符串 S ,q 次询问每次给出 l,r ,求 s[l..r] 的 Border . Border: 对于给定的串 s ,最大的 i 使得 s[1..i] = s[|s|-i+ ...
- 【codeforces666E】Forensic Examination 广义后缀自动机+树上倍增+线段树合并
题目描述 给出 $S$ 串和 $m$ 个 $T_i$ 串,$q$ 次询问,每次询问给出 $l$ .$r$ .$x$ .$y$ ,求 $S_{x...y}$ 在 $T_l,T_{l+1},...,T_r ...
- HDU 1568 Fibonacci(大数前4位)
转载自:http://blog.csdn.net/thearcticocean/article/details/47615241 分析:x=1234567.求其前四位数: log10(x)=log10 ...
- [hdu 1568] Fibonacci数列前4位
2007年到来了.经过2006年一年的修炼,数学神童zouyu终于把0到100000000的Fibonacci数列(f[0]=0,f[1]=1;f[i] = f[i-1]+f[i-2](i>=2 ...
- 在C#中对枚举进行位运算--枚举组合
由于枚举的基础类型类型为基本的数值类型,支持位运算,因此可以使用一个值表示多个枚举的组合,在定义枚举时需要指定枚举数为2的幂指数方便进行位运算,即枚举数为1,2,4,8…,或1,1<<1, ...
- POJ 1753 位运算+枚举
题意: 给出4*4的棋盘,只有黑棋和白棋,问你最少几步可以使棋子的颜色一样. 游戏规则是:如果翻动一个棋子,则该棋子上下左右的棋子也会翻一面,棋子正反面颜色相反. 思路: 都是暴搜枚举. 第一种方法: ...
- 洛谷P3783 [SDOI2017]天才黑客(前后缀优化建图+虚树+最短路)
题面 传送门 题解 去看\(shadowice\)巨巨写得前后缀优化建图吧 话说我似乎连线段树优化建图的做法都不会 //minamoto #include<bits/stdc++.h> # ...
随机推荐
- bzoj 1702: [Usaco2007 Mar]Gold Balanced Lineup 平衡的队列——map+hash+转换
Description N(1<=N<=100000)头牛,一共K(1<=K<=30)种特色, 每头牛有多种特色,用二进制01表示它的特色ID.比如特色ID为13(1101), ...
- mysql 索引最左原则原理
索引本质是一棵B+Tree,联合索引(col1, col2,col3)也是. 其非叶子节点存储的是第一个关键字的索引,而叶节点存储的则是三个关键字col1.col2.col3三个关键字的数据,且按照c ...
- Python 下调用C动态链接库 -- (转)
在linux开发的动态链接库需要被python调用,首先需要生成.so文件. 生成动态链接库的方法网上有很多,主要就是首先根据源文件编译生成.o,然后链接这些.o文件-shared生成.so.需要注意 ...
- C++学习之路(五):复制构造函数与赋值运算符重载
之前没有细想过两者的区别,今天对此进行简要记录,后续完善补充. 复制构造函数是在类对象被创建时调用的,但是赋值运算符是被已经存在的对象调用完成赋值操作. 复制构造函数只在对象实例化时才被调用,即在复制 ...
- linux===Ubuntu 上安装 Node.js
https://www.cnblogs.com/andfly/p/6681487.html
- python基础===理解Class的一道题
解题如下: from random import randint class Die(): def __init__(self,sides=6): self.sides = sides def rol ...
- xshell+xming连接服务器虚拟机启动mininet网络
困于vnc连实验室的服务器虚拟机,一直出现页面不稳定的情况,然后本机虚拟机又带不起来,今天跟学弟交流,知道了ssh连接服务器的办法,心情好晴朗! xshell下载和安装,xshell使用 xshell ...
- 【UOJ#9】vfk的数据
我感觉这题可以出给新高一玩2333 #include<bits/stdc++.h> #define N 10005 using namespace std; string s[N]; in ...
- tableView选中行的调用顺序/ 取消选中Cell
UITableViewCell它有两个属性highLighted.selected.很明显一个是高亮状态, 一个是选中状态. UITableViewCell, 对应的2个方法 // 高亮状态调用的方法 ...
- [caffe error] undefined reference to `inflateValidate@ZLIB_1.2.9'
undefined reference to `inflateValidate@ZLIB_1.2.9' Makefile.config添加一行LINKFLAGS := -Wl,-rpath,$(HOM ...