题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6186

题意:给了n个数,然后有q个查询,每个查询要求我们删掉一个数,问删掉这个数后整个序列的与值,或值,异或值的和。

解法:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
int n, m, a[maxn], sum1[maxn][2], sum2[maxn][2], sum3[maxn][2]; int main()
{
while(~scanf("%d %d", &n,&m))
{
for(int i=1; i<=n; i++) scanf("%d", &a[i]);
sum1[1][0] = sum2[1][0] = sum3[1][0] = a[1];
for(int i=2; i<=n; i++){
sum1[i][0] = sum1[i-1][0]&a[i];
sum2[i][0] = sum2[i-1][0]|a[i];
sum3[i][0] = sum3[i-1][0]^a[i];
}
sum1[n][1] = sum2[n][1] = sum3[n][1] = a[n];
for(int i=n-1; i>=1; i--){
sum1[i][1] = sum1[i+1][1]&a[i];
sum2[i][1] = sum2[i+1][1]|a[i];
sum3[i][1] = sum3[i+1][1]^a[i];
}
while(m--)
{
int idx;
scanf("%d", &idx);
int ans = INT_MAX;
if(idx > 1) ans &= sum1[idx-1][0];
if(idx < n) ans &= sum1[idx+1][1];
printf("%d ", ans);
ans = 0;
if(idx > 1) ans |= sum2[idx-1][0];
if(idx < n) ans |= sum2[idx+1][1];
printf("%d ", ans);
ans = 0;
if(idx > 1) ans ^= sum3[idx-1][0];
if(idx < n) ans ^= sum3[idx+1][1];
printf("%d\n", ans);
}
}
return 0;
}

HDU 6186 CS Course 前缀和,后缀和的更多相关文章

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

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

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

    http://acm.hdu.edu.cn/showproblem.php?pid=6186 题意:给出n个数,共有n次询问,每次询问给出一个数p,求除去第p个数后的n-1个数的&.|.^值. ...

  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. A + B for you again HDU - 1867(最大前缀&最大后缀的公共子缀&kmp删除法)

    Problem Description Generally speaking, there are a lot of problems about strings processing. Now yo ...

  6. HDU6025 Coprime Sequence —— 前缀和 & 后缀和

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6025 Coprime Sequence Time Limit: 2000/1000 MS (Java/ ...

  7. kmp(最长前缀与后缀)

    http://acm.hdu.edu.cn/showproblem.php?pid=1358 Period Problem Description For each prefix of a given ...

  8. 递归算法(二)——前缀转后缀

    源码:pretopost.cpp #include "stdafx.h" #include <stdio.h> #include <stack> /**** ...

  9. POJ 2752 Seek the Name, Seek the Fame (KMP的next函数,求前缀和后缀的匹配长度)

    给一个字符串S,求出所有前缀,使得这个前缀也正好是S的后缀.升序输出所有情况前缀的长度.KMP中的next[i]的意义就是:前面长度为i的子串的前缀和后缀的最大匹配长度.明白了next[i],那么这道 ...

随机推荐

  1. 【bzoj3312】[Usaco2013 Nov]No Change 状态压缩dp+二分

    题目描述 Farmer John is at the market to purchase supplies for his farm. He has in his pocket K coins (1 ...

  2. 【bzoj1901】Zju2112 Dynamic Rankings 离散化+主席树+树状数组

    题目描述 给定一个含有n个数的序列a[1],a[2],a[3]……a[n],程序必须回答这样的询问:对于给定的i,j,k,在a[i],a[i+1],a[i+2]……a[j]中第k小的数是多少(1≤k≤ ...

  3. hdu 1848(Fibonacci again and again)(SG博弈)

    Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  4. COGS 705——回家

    描述 USACO 2.4.4 现在是晚餐时间,而母牛们在外面分散的牧场中. 农民约翰按响了电铃,所以她们开始向谷仓走去. 你的工作是要指出哪只母牛会最先到达谷仓(在给出的测试数据中,总会有且只有一只最 ...

  5. BZOJ3571 & 洛谷3236:[HNOI2014]画框——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=3571 https://www.luogu.org/problemnew/show/P3236 小T ...

  6. React Patterns

    Contents Stateless function JSX spread attributes Destructuring arguments Conditional rendering Chil ...

  7. SELECT LOCK IN SHARE MODE and FOR UPDATE

    Baronwrote nice article comparing locking hints in MySQL and SQL Server. In MySQL/Innodb LOCK IN SHA ...

  8. Machine Learning CodeForces - 940F (带修改的莫队)

    You come home and fell some unpleasant smell. Where is it coming from? You are given an array a. You ...

  9. lnmp git ruby sass 安装

    1 cd .. 2 ls 3 cd mzx/ 4 ls 5 cd 桌面 6 cd lnmp1.4-full/ //到lnmp 的官网上下载后,根据官网的提示来安装lump 7 ls 8 install ...

  10. Ubuntu修改系统语言为英文可支持中文

    简单来说,就行修改/etc/default/locale文件,设置语言位UTF-8,如果没有这个语言,就执行命令locale-gen en_US.UTF-8进行安装,没有即时生效的话就重启. 查看当前 ...