明天后天是南昌赛了嘤嘤嘤,这几天就先不更新每日题目了,以后补题嘤嘤嘤。

今天和队友做了一套2017年广西邀请赛,5个题还是有点膨胀......

  好了,先来说一下有意思的题目吧......

CS Course

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3450    Accepted Submission(s): 1287

Problem Description
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,⋯,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 ap.

 
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≤105

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

After that there are q positive integers p1,p2,⋯,pqin q lines, 1≤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 ap in a line.
 
Sample Input
3 3
1 1 1
1
2
3
 
Sample Output
1 1 0
1 1 0
1 1 0
 
Source
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6543 6542 6541 6540 6539 
 
本题思路:我一开始上来就一发暴力,结果超时了,后来和队友讨论了一下,得出 ^ 可以逆着运算,也就是如果x ^ y = z,那么y 就可以用 z ^ x 得到,&和 | 我们打算将所有位置出现0和1的次数统计和,然后删除数字的时候删除对应数字上的0和1的个数,判断&和|即可。后来没有实现这个,而是用后缀数组和前缀数组实现,接着进行相应的位运算就行了,第一次做到这类型的思维题,所以今天先写一发博客记录。
参考代码:

#include <cstdio>
using namespace std; const int maxn = + ;
int c[maxn], _and1[maxn], _and2[maxn], _or1[maxn], _or2[maxn], _xor1[maxn], _xor2[maxn]; int main() {
int n, p, q, ans1, ans2, ans3;
while(~scanf("%d %d", &n, &p)) {
for(int i = ; i <=n; i ++) {
scanf("%d", &c[i]);
}
_and1[] = _or1[] = _xor1[] = c[];
_and2[n] = _or2[n] = _xor2[n] = c[n];
for(int i = ; i <= n; i ++) {
_and1[i] = _and1[i - ] & c[i];
_or1[i] = _or1[i - ] | c[i];
_xor1[i] = _xor1[i - ] ^ c[i];
}
for(int i = n - ; i >= ; i --) {
_and2[i] = _and2[i + ] & c[i];
_or2[i] = _or2[i + ] | c[i];
_xor2[i] = _xor2[i + ] ^ c[i];
} for(int i = ; i < p; i ++) {
scanf("%d", &q);
if(q == ) {
ans1 = _and2[];
ans2 = _or2[];
ans3 = _xor2[];
} else if(q == n) {
ans1 = _and1[n - ];
ans2 = _or1[n - ];
ans3 = _xor2[n - ];
} else {
ans1 = _and1[q - ] & _and2[q + ];
ans2 = _or1[q - ] | _or2[q + ];
ans3 = _xor1[q - ] ^ _xor2[q + ];
}
printf("%d %d %d\n", ans1, ans2, ans3);
}
}
return ;
}

HDU.6186.CSCource.(前缀和数组和后缀和数组)的更多相关文章

  1. HDU 5442 Favorite Donut(暴力 or 后缀数组 or 最大表示法)

    http://acm.hdu.edu.cn/showproblem.php?pid=5442 题意:给出一串字符串,它是循环的,现在要选定一个起点,使得该字符串字典序最大(顺时针和逆时针均可),如果有 ...

  2. 【HDU 5030】Rabbit's String (二分+后缀数组)

    Rabbit's String Problem Description Long long ago, there lived a lot of rabbits in the forest. One d ...

  3. Java数据结构和算法(六)——前缀、中缀、后缀表达式

    前面我们介绍了三种数据结构,第一种数组主要用作数据存储,但是后面的两种栈和队列我们说主要作为程序功能实现的辅助工具,其中在介绍栈时我们知道栈可以用来做单词逆序,匹配关键字符等等,那它还有别的什么功能吗 ...

  4. Java数据结构和算法(六):前缀、中缀、后缀表达式

    前面我们介绍了三种数据结构,第一种数组主要用作数据存储,但是后面的两种栈和队列我们说主要作为程序功能实现的辅助工具,其中在介绍栈时我们知道栈可以用来做单词逆序,匹配关键字符等等,那它还有别的什么功能吗 ...

  5. [TJOI2015]弦论(后缀数组or后缀自动机)

    解法一:后缀数组 听说后缀数组解第k小本质不同的子串是一个经典问题. 把后缀排好序后第i个串的本质不同的串的贡献就是\(n-sa[i]+1-LCP(i,i-1)\)然后我们累加这个贡献,看到哪一个串的 ...

  6. hdu 6200 mustedge mustedge(并查集+树状数组 或者 LCT 缩点)

    hdu 6200 mustedge mustedge(并查集+树状数组 或者 LCT 缩点) 题意: 给一张无向连通图,有两种操作 1 u v 加一条边(u,v) 2 u v 计算u到v路径上桥的个数 ...

  7. 温故而知新_C语言_前缀++(--)和后缀++(--)

    前缀++(--)和后缀++(++)是有区别的. 再单独使用的时候是没有区别的,都是自身递增或者递减1. 但是综合使用起来会一样吗? 下面的例子都是++,替换成--也是一样,道理都是一样的. 请先看下面 ...

  8. HDU 1024 A - Max Sum Plus Plus DP + 滚动数组

    http://acm.hdu.edu.cn/showproblem.php?pid=1024 刚开始的时候没看懂题目,以为一定要把那n个数字分成m对,然后求m对中和值最大的那对 但是不是,题目说的只是 ...

  9. HDU 5792:World is Exploding(树状数组求逆序对)

    http://acm.hdu.edu.cn/showproblem.php?pid=5792 World is Exploding Problem Description   Given a sequ ...

随机推荐

  1. wepy-数据双向绑定input

    初入wepy,发现wepy和vue神似,但还是有不一样的地方,例如v-model数据双向绑定 场景: 一个input搜索框,用户输入内容,点击“叉叉”按钮,输入的内容全部清空,这是一个很常见的场景 j ...

  2. JavaScript三元运算符以及运算符顺序

    三目运算符(三元运算符) 三目运算符:运算符需要三个操作 语法:表达式1?表达式2:表达式3 表达式1是一个条件,值为Boolean类型 若表达式1的值为true,则执行表达式2的操作,并且以表达式2 ...

  3. PHP入门培训教程 PHP变量的使用

      很多朋友在编写PHP程序的时候有时候对变量总有着不能确定的问题,而且也有很多问题就是因为变量的处理不当所造成的.这里兄弟连PHP培训 小编,就PHP变量系统说一下. PHP的变量分为全局变量与局部 ...

  4. 【rust】rust安装,运行第一个Rust 程序 (1)

    安装 Rust 在 Unix 类系统如 Linux 和 macOS 上,打开终端并输入: curl https://sh.rustup.rs -sSf | sh 回车后安装过程出现如下显示: info ...

  5. C# Asp.NET实现上传大文件(断点续传)

    以ASP.NET Core WebAPI 作后端 API ,用 Vue 构建前端页面,用 Axios 从前端访问后端 API ,包括文件的上传和下载. 准备文件上传的API #region 文件上传  ...

  6. 大文件上传-大视频上传,T级别的,求解决方案

    第一点:Java代码实现文件上传 FormFile file = manform.getFile(); String newfileName = null; String newpathname =  ...

  7. BZOJ 2427: [HAOI2010]软件安装 tarjan + 树形背包

    Description 现在我们的手头有N个软件,对于一个软件i,它要占用Wi的磁盘空间,它的价值为Vi.我们希望从中选择一些软件安装到一台磁盘容量为M计算机上,使得这些软件的价值尽可能大(即Vi的和 ...

  8. vue使用过滤器 filters:{}

    在项目开发过程中,经常会用到过滤器,下面就来说说我用的用法 我从后台获取到一个时间字段,是2017-03-23的格式,但是我要的是年月日分开显示,那就要用到过滤器了 在没有用过滤器的时候,是这样的: ...

  9. Angular项目 Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed.报错

    在angular的项目里,一不小心就会出现这个错误[ngRepeat:dupes] ,这个问题是因为内容有重复引起的解决起来挺简单 在对应的ng-repeat指令中增加track by $index, ...

  10. opencv_python_基本图像处理

    https://www.e-learn.cn/content/python/2694135 https://blog.csdn.net/Eastmount/article/details/817488 ...