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

今天和队友做了一套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的个数,判断&和|即可。后来没有实现这个,而是用后缀数组和前缀数组实现,接着进行相应的位运算就行了,第一次做到这类型的思维题,所以今天先写一发博客记录。
参考代码:

  1. #include <cstdio>
  2. using namespace std;
  3.  
  4. const int maxn = + ;
  5. int c[maxn], _and1[maxn], _and2[maxn], _or1[maxn], _or2[maxn], _xor1[maxn], _xor2[maxn];
  6.  
  7. int main() {
  8. int n, p, q, ans1, ans2, ans3;
  9. while(~scanf("%d %d", &n, &p)) {
  10. for(int i = ; i <=n; i ++) {
  11. scanf("%d", &c[i]);
  12. }
  13. _and1[] = _or1[] = _xor1[] = c[];
  14. _and2[n] = _or2[n] = _xor2[n] = c[n];
  15. for(int i = ; i <= n; i ++) {
  16. _and1[i] = _and1[i - ] & c[i];
  17. _or1[i] = _or1[i - ] | c[i];
  18. _xor1[i] = _xor1[i - ] ^ c[i];
  19. }
  20. for(int i = n - ; i >= ; i --) {
  21. _and2[i] = _and2[i + ] & c[i];
  22. _or2[i] = _or2[i + ] | c[i];
  23. _xor2[i] = _xor2[i + ] ^ c[i];
  24. }
  25.  
  26. for(int i = ; i < p; i ++) {
  27. scanf("%d", &q);
  28. if(q == ) {
  29. ans1 = _and2[];
  30. ans2 = _or2[];
  31. ans3 = _xor2[];
  32. } else if(q == n) {
  33. ans1 = _and1[n - ];
  34. ans2 = _or1[n - ];
  35. ans3 = _xor2[n - ];
  36. } else {
  37. ans1 = _and1[q - ] & _and2[q + ];
  38. ans2 = _or1[q - ] | _or2[q + ];
  39. ans3 = _xor1[q - ] ^ _xor2[q + ];
  40. }
  41. printf("%d %d %d\n", ans1, ans2, ans3);
  42. }
  43. }
  44. return ;
  45. }

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. LOJ#3097 [SNOI2019]通信 最小费用最大流+cdq分治/主席树/分块优化建图

    瞎扯 我们网络流模拟赛(其实是数据结构模拟赛)的T2. 考场上写主席树写自闭了,直接交了\(80pts\)的暴力,考完出来突然发现: woc这个题一个cdq几行就搞定了! 题意简述 有\(n\)个哨站 ...

  2. 【学习笔记】Minkowski和

    这还是个被我咕了N久的玩意 Minkowski和是一个奇怪的玩意 他长这样 $S={a+b \| a \in A , b \in B}$ AB可以是点集也可是向量集(显然) 他可以处理一些奇怪的东西 ...

  3. ZROI 19.07.30 简单图论/kk

    1.最短路 NOI2019 D2T1 我被这题送Fe了/lb 只有zz才会写二维线段树,比如我. 实际上你只需要矩形取min就可以. kd-tree可以随便过,最慢的点\(0.1s\). 另外一种简单 ...

  4. 一个简单SpringBoot应用的pom.xml文件

    <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...

  5. java:投个票程序

    投票城市用到了:system.in, 正则pattern,matcher,排序接口comparable 复写compareTo排序方法 一个班级在选班长,按序号进行投票,并将票数最高的放在第一位显示 ...

  6. GDKOI2016总结——被虐之旅

    前言 一个被虐的旅程... 这次GDKOI的比赛虽然基本全上暴力,但是居然只有两道题得了分:30+30=60!我感觉整个人都不好了... day0 在去广州的路上,本来心情很好,但是坐在我斜后面的那位 ...

  7. python 布尔判断并做需要的返回值

  8. 阿里云视频云正式支持AV1编码格式 为视频编码服务降本提效

    今天我们要说的 AV1 可不是我们平时说的 .AVI 文件格式,它是由AOM(Alliance for Open Media,开放媒体联盟)制定的一个开源.免版权费的视频编码格式,可以解决H.265昂 ...

  9. Andorid 手机WIFI连接的Mac地址和IP地址

    public static String getInfo()     {        WifiManager wifi = (WifiManager) getSystemService(Contex ...

  10. 实用工具/API

    实用工具/API PNG图片无损压缩 在线给图片加水印 随机密码生成 随机头像生成 微博一键清理工具 CSS压缩 在线工具 免费虚拟主机 技术摘要 https://github.com/biezhi/ ...