2017ICPC/广西邀请赛1005(水)HDU6186
CS Course
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 593 Accepted Submission(s): 288
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
,a
2
,⋯,a
n
, 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
.
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
,a
2
,⋯,a
n
follows in a line, 0≤ai
≤10
9
for each i in range[1,n].
After that there are q positive integers p1
,p
2
,⋯,p
q
in q lines, 1≤pi
≤n
for each i in range[1,q].
in a line.
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn= 1e5 + ;
const int inf = 0x3f3f3f3f;
typedef long long ll;
int n,m;
int sum1[maxn],sum2[maxn],sum3[maxn];
int rsum1[maxn],rsum2[maxn],rsum3[maxn];
int a[maxn];
int main(int argc, char const *argv[])
{
while(scanf("%d %d",&n,&m)==)
{
scanf("%d",&a[]);
sum1[]=sum2[]=sum3[]=a[];
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum1[i]=sum1[i-] & a[i];
sum2[i]=sum2[i-] | a[i];
sum3[i]=sum3[i-] ^ a[i];
}
rsum1[n]=rsum2[n]=rsum3[n]=a[n];
for(int i=n-;i>=;i--)
{
rsum1[i]=rsum1[i+] & a[i];
rsum2[i]=rsum2[i+] | a[i];
rsum3[i]=rsum3[i+] ^ a[i];
//cout<<rsum1[i]<<" "<<rsum2[i]<<" "<<rsum3[i]<<endl;
}
int q;
while(m--)
{
scanf("%d",&q);
if(q==)
printf("%d %d %d\n",rsum1[],rsum2[],rsum3[]);
else if(q == n)
printf("%d %d %d\n",sum1[n-],sum2[n-],sum3[n-]);
else
printf("%d %d %d\n",sum1[q-] & rsum1[q+],sum2[q-]|rsum2[q+],sum3[q-]^rsum3[q+]);
}
}
return ;
}
2017ICPC/广西邀请赛1005(水)HDU6186的更多相关文章
- 2017ICPC/广西邀请赛1001(水)HDU6181
A Math Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 2017 ICPC 广西邀请赛1005 CS Course
CS Course Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- 2017ACM/ICPC广西邀请赛 1005 CS Course
CS Course Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- 2017 ICPC 广西邀请赛1004 Covering
Covering Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 2017ACM/ICPC广西邀请赛-重现赛1005 CS course
2017-08-31 16:19:30 writer:pprp 这道题快要卡死我了,队友已经告诉我思路了,但是做题速度很缓慢,很费力,想必是因为之前 的训练都是面向题解编程的缘故吧,以后不能这样了,另 ...
- HDU 4847 陕西邀请赛A(水)
HDU 4847 Wow! Such Doge! pid=4847" style="">题目链接 题意:给定文本,求有几个doge,不区分大写和小写 思路:水题.直 ...
- 2017ACM/ICPC广西邀请赛-重现赛 1007.Duizi and Shunzi
Problem Description Nike likes playing cards and makes a problem of it. Now give you n integers, ai( ...
- 2017ACM/ICPC广西邀请赛-重现赛 1010.Query on A Tree
Problem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey A learne ...
- 2017ACM/ICPC广西邀请赛-重现赛 1004.Covering
Problem Description Bob's school has a big playground, boys and girls always play games here after s ...
随机推荐
- 搭建和测试 Redis 主备和集群
本文章只是自我学习用,不适宜转载. 1. Redis主备集群 1.1 搭建步骤 机器:海航云虚机(2核4GB内存),使用 Centos 7.2 64bit 操作系统,IP 分别是 192.168.10 ...
- vi 和vim 的区别
它们都是多模式编辑器,不同的是vim 是vi的升级版本,它不仅兼容vi的所有指令,而且还有一些新的特性在里面.vim的这些优势主要体现在以下几个方面:1.多级撤消我们知道在vi里,按 u只能撤消上次命 ...
- ssh简明安全规划
禁止使用口令只允许使用密钥建立 SSH 连接 1.创建 SSH KEY 使用ssh-keygen生成一个密钥对,并且将公钥注册到服务器的 $HOME/.ssh/authorized_keys 文件. ...
- 常用API接口汇总
下面列举了100多个国内常用API接口,并按照 笔记.出行.词典.电商.地图.电影.即时通讯.开发者网站.快递查询.旅游.社交.视频.天气.团队协作.图片与图像处理.外卖.消息推送.音乐.云.语义识别 ...
- 程序猿的日常——HashMap的相关知识
背景知识 哈希冲突 哈希是指通过某种方法把数据转变成特定的数值,数值根据mod对应到不同的单元上.比如在Java中,字符串就是通过每个字符的编码来计算.数字是本身对应的值等等,不过就算是再好的哈希方法 ...
- Hadoop 发行版本 Hortonworks 安装详解(一) 准备工作
一.前言 目前Hadoop发行版非常多,所有这些发行版均是基于Apache Hadoop衍生出来的,之所以有这么多的版本,完全是由Apache Hadoop的开源协议决定的:任何人可以对其进行修改,并 ...
- 执行PHP脚本时遇到 mysql_connect(): Headers and client library minor version mismatch的解决方法
把服务器从Windows迁移到了centos7.2,配置好PHP运行环境后,项目运行正常. 但在命令行中运行一个PHP脚本时,遇到了标题中显示的错误 使用 php -i | grep Client 得 ...
- 前端学习_01_css网页布局
引子 之前也自己陆陆续续地学了一些web方面的知识,包括前段和后端都有涉及到,自己也比较感兴趣,感谢peter老师,愿意无偿提供从零开始的教学,之前也看过peter老师的一些视频,节奏非常适合我,决心 ...
- linux下查看系统属性
inux下查看系统属性1.查看cpu信息查看所有cpu信息:cat /proc/cpuinfo查看cpu类型: grep "model name" /proc/cpuinfo2.查 ...
- Python函数返回不定数量的值
Python的函数是可以return多个值的,但其本质上还是返回单个值,只是利用了tuple的自动打包,将多个值打包成单个tuple返回. 使用代码验证: def func_a(): return 1 ...