CS Course HDU - 6186
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 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 ap.
Input
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 2≤n,q≤105
Then n non-negative integers a1,a2,⋯,an a1,a2,⋯,an follows in a line, 0≤ai≤109 0≤ai≤109 for each i in range[1,n].
After that there are q positive integers p1,p2,⋯,pq p1,p2,⋯,pqin q lines, 1≤pi≤n 1≤pi≤n for each i in range[1,q].
Output
Sample Input
3 3 1 1 1 1 2 3
Sample Output
1 1 0 1 1 0 1 1 0
题意:输入n和q两组数,n代表n个数,q代表q次询问,每次询问是输入一个数m,然后输出三个数,分别是除了第m个数以外的所有数的按位与按位或按位异或,三个值;
思路:开六个数组,直接模拟前缀和后缀暴力即可:
#include <stdio.h>
long long a[100005];
long long s1[100005] , S1[100005];
long long s2[100005] , S2[100005];
long long s3[100005] , S3[100005];
int main() {long long n , q , m;while(~scanf("%lld%lld",&n,&q)) {for(int i = 1; i <= n; i++) {scanf("%lld",&a[i]);}s1[1] = a[1];s2[1] = a[1];s3[1] = a[1];for(int i = 2; i <= n; i++) {//前缀 s1[i] = s1[i-1]|a[i];s2[i] = s2[i-1]&a[i];s3[i] = s3[i-1]^a[i];}S1[n] = a[n];S2[n] = a[n];S3[n] = a[n];for(int i = n - 1; i >= 1; i--) {//后缀 S1[i] = S1[i+1]|a[i];S2[i] = S2[i+1]&a[i];S3[i] = S3[i+1]^a[i];}for(int i = 0; i < q; i++) {scanf("%lld",&m);if(m == 1) {printf("%lld %lld %lld\n",S2[m+1] , S1[m+1] , S3[m+1]);}else if(m == n) {printf("%lld %lld %lld\n",s2[m-1] , s1[m-1], s3[m-1]);}else {printf("%lld %lld %lld\n",s2[m-1]&S2[m+1] , s1[m-1]|S1[m+1] , s3[m-1]^S3[m+1]);}}}return 0;
}
CS Course HDU - 6186相关推荐
- HDU 6186 CS Course
点击打开链接 CS Course Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU - 6186 CS Course(维护前缀+后缀)
题目链接:点击查看 题目大意:给出n个数以及m个查询,每个查询包括一个数字,要求输出除了该数字之外的位运算的"或和","与和"和"异或和" ...
- 【HDU - 6186】CS Course(按位与,按位或,按位异或的区间统计,二进制拆位)
题干: Little A has come to college and majored in Computer and Science. Today he has learned bit-opera ...
- HDU 6186 2017广西邀请赛:CS Course
题意: n个数,m次查询,每次给出一个p,求出除了第p个数以外其它所有数的且和,或和,异或和 统计下每个二进制位1的数量,例如z[5] = x表示有x个数第5个二进制位为1 之后每次查询只要check ...
- HDU 6186 CS Course(线段树区间操作)
Little A has come to college and majored in Computer and Science. Today he has learned bit-operation ...
- 2017ACM/ICPC广西邀请赛
2017ACM/ICPC广西邀请赛(感谢广西大学) 题号 题目 考点 难度 A A Math Problem 数论 签到题 B Color it C Counting Stars D Covering ...
- hdu 1174:爆头(计算几何,三维叉积求点到线的距离)
爆头 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...
- poj 2096 , zoj 3329 , hdu 4035 —— 期望DP
题目:http://poj.org/problem?id=2096 题目好长...意思就是每次出现 x 和 y,问期望几次 x 集齐 n 种,y 集齐 s 种: 所以设 f[i][j] 表示已经有几种 ...
- HDU 4685. Prince and Princess
链接 http://acm.hdu.edu.cn/showproblem.php?pid=4685 题意 nnn 个王子,mmm 个公主,每个王子可以娶他喜欢的公主中的一个,每个公主只能嫁个一个王子, ...
最新文章
- extra加ing_英语词汇学各个章节的内容
- 4.6 什么是神经风格迁移-深度学习第四课《卷积神经网络》-Stanford吴恩达教授
- DFT实训教程笔记2(bibili版本)- Scan synthesis practice
- val_loss突然变很大_女朋友突然变得很冷淡是怎么回事?该怎么办
- kafka 丢弃数据_Kafka史上最详细原理总结下
- 云原生开发者须具备的1+N技能,开启第二曲线
- Linux内核 eBPF基础:BCC (BPF Compiler Collection)
- mysql skip slave_MYSQL replication slave-skip-errors 详解
- hadoop与mysql的区别_数据库与hadoop与分布式文件系统的区别和联系
- 7.数电复刻 之 门电路
- 设置eMMC和DDR的工作频率
- python怎么打开h5文件_h5文件python
- java实现中文数字与阿拉伯数字互相转换
- 什么是promise?
- 自己动手设计一个简单的HTML网页
- Windows11 校园网连ftp登录上传作业失败
- 1.2 储存卡牌信息———自制卡牌游戏之旅
- D. Rescue Nibel(cf) 区间覆盖 + 组合数学
- php artisan 出错,使用php artisan serve命令获取错误
- Windows11任务管理器