http://acm.hdu.edu.cn/showproblem.php?pid=6186

题意:
给出n个数,共有n次询问,每次询问给出一个数p,求除去第p个数后的n-1个数的&、|、^值。

思路:
分别计算出&、|、^的前缀和后缀,将前缀和后缀相计算即可。

 #include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 1e5+; int n, q;
int a[maxn], prea[maxn], suffa[maxn], preo[maxn], suffo[maxn], prex[maxn], suffx[maxn]; int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d%d",&n,&q))
{
scanf("%d",&a[]);
prea[] = preo[] = prex[] = a[];
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
prea[i] = a[i] & prea[i-];
preo[i] = a[i] | preo[i-];
prex[i] = a[i] ^ prex[i-];
}
suffa[n] = suffo[n] = suffx[n] = a[n];
for(int i=n-;i>=;i--)
{
suffa[i] = a[i] & suffa[i+];
suffo[i] = a[i] | suffo[i+];
suffx[i] = a[i] ^ suffx[i+];
}
while(q--)
{
int pos; scanf("%d",&pos);
int ans1 = prea[pos-] & suffa[pos+];
int ans2 = preo[pos-] | suffo[pos+];
int ans3 = prex[pos-] ^ suffx[pos+];
if(pos==)
{
ans1 = suffa[pos+];
ans2 = suffo[pos+];
ans3 = suffx[pos+];
}
if(pos==n)
{
ans1 = prea[pos-];
ans2 = preo[pos-];
ans3 = prex[pos-];
}
printf("%d %d %d\n", ans1, ans2, ans3);
}
}
return ;
}

HDU 6186 CS Course(前缀+后缀)的更多相关文章

  1. HDU 6186 CS Course 前缀和,后缀和

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6186 题意:给了n个数,然后有q个查询,每个查询要求我们删掉一个数,问删掉这个数后整个序列的与值,或值 ...

  2. HDU 6186 CS Course【前后缀位运算枚举/线段树】

    [前后缀枚举] #include<cstdio> #include<string> #include<cstdlib> #include<cmath> ...

  3. HDU 6186 CS Course

    保存前缀后缀. 保存一下前缀和后缀,去掉第$i$个位置,就是$L[i-1]$和$R[i+1]$进行运算. #include<bits/stdc++.h> using namespace s ...

  4. HDU 6186 CS Course (连续位运算)

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

  5. POJ 2752 (KMP 所有可能长度的前缀后缀) Seek the Name, Seek the Fame

    题意: 求一个字符串的相同前缀后缀的所有可能的长度,这里该字符串其本身也算自己的前缀和后缀. 分析: 我们知道next数组的性质是,该字符之前的字符串的最大相同前缀后缀. 既然知道了最大的,即next ...

  6. hdu 3553 Just a String (后缀数组)

    hdu 3553 Just a String (后缀数组) 题意:很简单,问一个字符串的第k大的子串是谁. 解题思路:后缀数组.先预处理一遍,把能算的都算出来.将后缀按sa排序,假如我们知道答案在那个 ...

  7. hdoj 2594 Simpsons’ Hidden Talents 【KMP】【求串的最长公共前缀后缀】

    Simpsons' Hidden Talents Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  8. HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化

    HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化 n个节点n-1条线性边,炸掉M条边也就是分为m+1个区间 问你各个区间的总策略值最少的炸法 就题目本身而言,中规中矩的 ...

  9. 1280 前缀后缀集合(map)

    1280 前缀后缀集合 题目来源: Codility 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 一个数组包含N个正整数,其中有些是重复的.一个前缀后缀集是满足 ...

随机推荐

  1. css的小知识4

    ---恢复内容开始--- 一.单位 1.px就是一个基本单位     像素 2.em也是一个单位      用父级元素的字体大小乘以em前面的数字.如果父级没有就继承上一个父级直到body,如果bod ...

  2. Recurrent NN vs Recursive NN

    https://www.bilibili.com/video/av9770302/?p=8 李宏毅深度学习 图很清楚的反映出两者的不同 Recurrent可以看成Recursive的特殊形式,即以特定 ...

  3. 《PHP - CGI/Fastcgi/PHP-FPM》

    先说下我最近看到的一篇文章,哈哈哈,特别好玩. 一步步教你编写不可维护的 PHP 代码 之前一直知道 PHP 在 CGI 模式下运行.命令行下在 CLI 模式下运行. 但是 FPM 和 nginx 配 ...

  4. what's the 颈线

    出自 MBA智库百科(https://wiki.mbalib.com/) 什么是颈线 颈线一种支撑线,出现在头肩顶形态中,是连接两个低点的平行线. 什么是“头肩顶”型态 一个完美的“头肩顶”走势,可以 ...

  5. python进阶之 进程&线程区别

    1.进程创建方式 import time import os from multiprocessing import Process def func (): time.sleep(1) print( ...

  6. css设置input获得焦点的样式

    input:focus{ 样式; } 这样就ok

  7. PHP多维数组转一维

    目录 1. array_column函数 2. array_walk函数 3. array_map函数 4. foreach循环 5. array_map变种 参考:https://www.awaim ...

  8. utf8 vs utf8mb4

    UTF-8 is a variable-length encoding. In the case of UTF-8, this means that storing one code point re ...

  9. random函数的使用

    random作为随机函数用处很多,在Python里面也经常使用,特别是处理一些随机事件的时候,特别好用! 废话不多说,直接看下面的例子: random.randomrandom.random()   ...

  10. vue 之iview

    iView-admin2.0:https://admin.iviewui.com/ 组件:https://www.iviewui.com/docs/guide/install