2017ACM/ICPC广西邀请赛 1005 CS Course
CS Course
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total
Submission(s): 0 Accepted Submission(s): 0
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
,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].
indicates the result of bit-operations(and, or, xor) of all non-negative
integers except a
in a line.
1 1 1
1
2
3
1 1 0
1 1 0
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cstring>
#include <math.h>
using namespace std;
#define MAXN 0xffffff
int a[];
int qy[],hy[];//与的前缀 后缀
int qh[],hh[];//或的前缀 后缀
int qyh[],hyh[];//异或的
int main()
{
// & | ^
int n,q;
while(~scanf("%d%d",&n,&q))
{
scanf("%d",&a[]);
qy[]=qh[]=qyh[]=a[];
for(int i=; i<=n; ++i)
{
scanf("%d",&a[i]);
qy[i]=a[i]&qy[i-];
qh[i]=a[i]|qh[i-];
qyh[i]=a[i]^qyh[i-];
}
hy[n]=hh[n]=hyh[n]=a[n];
// printf("%d ",a[n]);
for(int i=n-; i>; --i)
{
hy[i]=a[i]&hy[i+];
hh[i]=a[i]|hh[i+];
hyh[i]=a[i]^hyh[i+];
}
/* for(int i=1; i<=n; ++i)
{
printf("%d ",hh[i]);
}*/
while(q--)
{
int m;
scanf("%d",&m);
// printf("%d %d %d %d %d %d\n",qy[m-1],hy[m+1],qh[m-1],hh[m+1],qyh[m-1],hyh[m+1]);
if(m==)
{
printf("%d %d %d\n",hy[m+],hh[m+],hyh[m+]);
}
else if(m==n)
{
printf("%d %d %d\n",qy[m-],qh[m-],qyh[m-]);
}
else
{
printf("%d %d %d\n",qy[m-]&hy[m+],qh[m-]|hh[m+],qyh[m-]^hyh[m+]);
} }
}
return ;
}
2017ACM/ICPC广西邀请赛 1005 CS Course的更多相关文章
- 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
2017-08-31 16:19:30 writer:pprp 这道题快要卡死我了,队友已经告诉我思路了,但是做题速度很缓慢,很费力,想必是因为之前 的训练都是面向题解编程的缘故吧,以后不能这样了,另 ...
- 2017ACM/ICPC广西邀请赛 CS Course
题意:删除指定数字,求剩下数字的与或非值 解法:保存一下前缀和后缀 #include <iostream> #include <stdio.h> #include <ve ...
- 2017ACM/ICPC广西邀请赛-重现赛
HDU 6188 Duizi and Shunzi 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 思路: 签到题,以前写的. 实现代码: #inc ...
- 2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)
上一场CF打到心态爆炸,这几天也没啥想干的 A Math Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/3 ...
- 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 ...
- HDU 6191 2017ACM/ICPC广西邀请赛 J Query on A Tree 可持久化01字典树+dfs序
题意 给一颗\(n\)个节点的带点权的树,以\(1\)为根节点,\(q\)次询问,每次询问给出2个数\(u\),\(x\),求\(u\)的子树中的点上的值与\(x\)异或的值最大为多少 分析 先dfs ...
随机推荐
- 项目Beta冲刺(团队)-凡事预则立
所属课程 软件工程1916|W(福州大学) 作业要求 项目Beta冲刺(团队)-凡事预则立 团队名称 基于云的胜利冲锋队 作业目标 为 Beta 冲刺规划安排 1.讨论组长是否重选的议题和结论 由于我 ...
- SSH——ssh_exchange_identification: read: Connection reset by peer
前言 ssh远程连接出错 步骤 查看ssh的详细信息 [root@pre-nginx02 ~]# ssh -v 192.168.1.164 OpenSSH_6.6.1, OpenSSL 1.0.1e- ...
- 四.python基础数据类型
一.什么是数据类型? 什么是数据类型? 我们人类可以很容易的分清数字与字符的区别,但是计算机并不能呀,计算机虽然很强大,但从某种角度上看又很傻,除非你明确的告诉它,1是数字,“汉”是文字,否则它是分不 ...
- js 做留言提交
如下是留言提交源码 功能:点击按钮或点击enter键可以提交内容扩展:ctrlKey\shiftKey\altKye 可以将如上三个参数与oEvent.keyCode == 13 进行与操作可以得到 ...
- Break关键字和Continue关键字
1.Break关键字 在循环体内,只要代码遇到break,程序立马结束当前循环. 当前循环指的是break语句所在的循环体.(直接跳到大括号外) // 例1: 1到10,第一是数字是2的倍数,控制台输 ...
- 均值不等式中的一则题目$\scriptsize\text{$(a+\cfrac{1}{a})^2+(b+\cfrac{1}{b})^2\ge \cfrac{25}{2}$}$
例题已知正数\(a.b\)满足条件\(a+b=1\),求\((a+\cfrac{1}{a})^2+(b+\cfrac{1}{b})^2\)的最小值: 易错方法\((a+\cfrac{1}{a})^2+ ...
- pycharm+gitee【代码上传下载】实战(windows详细版)
pycharm+gitee环境搭建好以后应该如何进行代码上传下载操作呢?举几个例子,此文会一直更新 环境:2019社区版pycharm+gitee+git 系统:windows系统 一.代码上传功能 ...
- python 获取 一个正整数的二进制
#coding=utf- def getbin(a): out = "" # 辗转相除法 ): div = a mod = a % out += str(mod) ): break ...
- 【AtCoder】 ARC 102
link C-Triangular Relationship 发现要么全部是\(K\)的倍数,要么全部是模\(K\)余\(K/2,(K=2n)\) #include<bits/stdc++.h& ...
- 每天有300W的pv,我们单台机器的QPS为58,大概需要部署几台这样机器?
每天有300W的pv,我们单台机器的QPS为58,大概需要部署几台这样机器? 一.总结 一句话总结: ( 3000000 * 0.8 ) / (86400 * 0.2 ) = 139 (QPS) 13 ...