CS Course

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total
Submission(s): 0    Accepted Submission(s): 0

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,⋯,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
 
 
题解:这道题目  要注意的是   与   或   异或  的操作    不受前后循序的影响的 
我是使用了6个数组   保存了数组与   或   异或的前缀和   和   后缀    
 #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的更多相关文章

  1. 2017 ICPC 广西邀请赛1005 CS Course

    CS Course Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. 2017ACM/ICPC广西邀请赛-重现赛1005 CS course

    2017-08-31 16:19:30 writer:pprp 这道题快要卡死我了,队友已经告诉我思路了,但是做题速度很缓慢,很费力,想必是因为之前 的训练都是面向题解编程的缘故吧,以后不能这样了,另 ...

  3. 2017ACM/ICPC广西邀请赛 CS Course

    题意:删除指定数字,求剩下数字的与或非值 解法:保存一下前缀和后缀 #include <iostream> #include <stdio.h> #include <ve ...

  4. 2017ACM/ICPC广西邀请赛-重现赛

    HDU 6188 Duizi and Shunzi 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 思路: 签到题,以前写的. 实现代码: #inc ...

  5. 2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)

    上一场CF打到心态爆炸,这几天也没啥想干的 A Math Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/3 ...

  6. 2017ACM/ICPC广西邀请赛-重现赛 1007.Duizi and Shunzi

    Problem Description Nike likes playing cards and makes a problem of it. Now give you n integers, ai( ...

  7. 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 ...

  8. 2017ACM/ICPC广西邀请赛-重现赛 1004.Covering

    Problem Description Bob's school has a big playground, boys and girls always play games here after s ...

  9. HDU 6191 2017ACM/ICPC广西邀请赛 J Query on A Tree 可持久化01字典树+dfs序

    题意 给一颗\(n\)个节点的带点权的树,以\(1\)为根节点,\(q\)次询问,每次询问给出2个数\(u\),\(x\),求\(u\)的子树中的点上的值与\(x\)异或的值最大为多少 分析 先dfs ...

随机推荐

  1. python开发笔记之zip()函数用法详解

    今天分享一篇关于python下的zip()函数用法. zip()是Python的一个内建函数,它接受一系列可迭代的对象作为参数,将对象中对应的元素按顺序组合成一个tuple,每个tuple中包含的是原 ...

  2. myeclipse常用快捷(持续更新)

    最近开始转用myeclipse,总结一下快捷方式:(我喜欢用的) [Ctrl+O]    显示类中方法和属性的大纲,能快速定位类的方法和属性,在查找Bug时非常有用. [Ctrl+M]    窗口最大 ...

  3. 51Node1228序列求和 ——自然数幂和模板&&伯努利数

    伯努利数法 伯努利数原本就是处理等幂和的问题,可以推出 $$ \sum_{i=1}^{n}i^k={1\over{k+1}}\sum_{i=1}^{k+1}C_{k+1}^i*B_{k+1-i}*(n ...

  4. 6、Hadoop 2.6.0 运行

    运行方式 Local (Standalone) Mode Pseudo-Distributed Mode Fully-Distributed Mode Standalone Operation $ s ...

  5. hhhhh臭不要脸//捂脸)多不好意思啊you进步惹

    如题↑↑↑ 千万不要相信题目 还是看图说话吧↓↓↓ 我真的蒟蒻啊,,,准确率在70边缘徘徊,卑微☹ 不过还是侥幸地进入了前 30 名! 今天七夕欸,然鹅,,, qq空间里面弥漫着恋爱的酸臭味 香气,‘ ...

  6. Intellij IDEA 自动清除无效 import 和 清除无效 import 的快捷键

    可以settings-general-auto import-java项,勾选optimize imports on the fly,在当前项目下会自动清除无效的import,而且这个是随时自动清除的 ...

  7. PL/SQL Developer插入数据到数据库出现数据中文乱码

    问题描述: 使用PL/SQL Developer往Oracle数据库插入数据,出现中文乱码! 解决办法: 1.执行脚本 select userenv('language') from dual; 结果 ...

  8. RocketMq重复消费问题排查

    前情 出现了重复消费的问题,同一个消息被重复消费了多次,导致了用户端收到了多条重复的消息,最终排查发现,是因为消费者在处理消息的方法onMessage中有异常没有捕获到,导致异常上抛,被consume ...

  9. [Web 安全] WASC 和 OWASP两个web安全方面组织机构介绍

    copy from :  http://blog.sina.com.cn/s/blog_70b7aab9010126mn.html WASC 和 OWASP.这两个组织在呼吁企业加强应用安全意识和指导 ...

  10. 进程、线程、IP、端口间关系

    进程.线程.IP.端口间关系 进程是指在系统中正在运行的一个应用程序: 线程是系统分配处理器时间资源的基本单元,或者说进程之内独立执行的一个单元. 对于操作系统而言,其调度单元是线程.一个进程至少包括 ...