HDU6186CS Course前缀和
来源:互联网 发布:高中封闭式管理 知乎 编辑:程序博客网 时间:2024/05/29 18:39
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6186
6186 CS Course
Time Limit: 4000/2000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 466
Accepted Submission(s): 232
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 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≤10^5
Then n non-negative integers a1,a2,⋯,an follows in a line, 0≤ai≤10
^9 for each i in range[1,n].
After that there are q positive integers p1,p2,⋯,pq in 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
题意:给一个序列a,求除去pk个的与,或,异或
思路:分别求前缀数组和后缀数组,在pi的两边分别进行运算,再将这两个结果进行运算即可。
附上ac代码
#include<stdio.h>using namespace std;const int maxn = 100005;int a[maxn];int x1[maxn], y1[maxn], z1[maxn];int x2[maxn], y2[maxn], z2[maxn];int main(){ int n, m; while(scanf("%d%d", &n, &m) != EOF){ for(int i = 1; i <= n; i++) scanf("%d", &a[i]); //前缀和 x1[1] = y1[1] = z1[1] = a[1]; for(int i = 2; i <= n; i++){ x1[i] = a[i] & x1[i-1]; y1[i] = a[i] | y1[i-1]; z1[i] = a[i] ^ z1[i-1]; } //后缀和 x2[n] = y2[n] = z2[n] = a[n]; for(int i = n - 1; i >= 1; i--){ x2[i] = a[i] & x2[i+1]; y2[i] = a[i] | y2[i+1]; z2[i] = a[i] ^ z2[i+1]; } for(int i = 1; i <= m; i++){ int q; scanf("%d", &q); if(q == 1) printf("%d %d %d\n", x2[q+1], y2[q+1], z2[q+1]); else if(q == n) printf("%d %d %d\n", x1[q-1], y1[q-1], z1[q-1]); else{ printf("%d %d %d\n", x1[q-1] & x2[q+1], y1[q-1] | y2[q+1], z1[q-1] ^ z2[q+1]); } } } return 0;}
- HDU6186CS Course前缀和
- hdu6186-思维&前缀和&后缀和-CS Course
- HDU6186 | 2017广西邀请赛 CS Course (前缀和后缀)
- 2017广西邀请赛/hdu6186 CS Course (维护前缀和后缀)
- hdu 6186 CS Course (前缀+后缀)
- hdu 6186 CS Course 前缀后缀问题
- 前缀和
- 前缀和
- 前缀和
- 前缀和
- 前缀和
- 【位运算知识+前缀思路+后缀思路】CS Course HDU
- 前缀和:区间和
- 前缀和后缀和
- Course
- course
- course 和heading的区别
- 前缀++和后缀++
- 成为快乐高产的程序员的小诀窍。
- 安装
- 机器学习之非监督学习
- AbstractQueuedSynchronizer源码剖析(四)- 不响应中断的共享锁
- 微信小程序----组件之text
- HDU6186CS Course前缀和
- html5播放器的示例代码
- 如何在linux下开启FTP服务
- startActivity时报错Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVI
- [机器学习实验4]正则化(引入惩罚因子)
- 《重构-改善既有代码的设计》知识精选——代码坏味道
- 2017智慧树 创践大学生创新创业实务答案
- Wdatepicker日期控件的使用指南
- opencv 矩阵元素排序(代码)