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. webpack-dev-server 本地代理proxy

    proxy: [ { context: ['/user', '/rights', '/resource/getAdNotice'], target: 'https://plus.m.jd.com', ...

  2. python开发笔记-DataFrame的使用

    今天详细做下关于DataFrame的使用,以便以后自己可以翻阅查看 DataFrame的基本特征: 1.是一个表格型数据结构 2.含有一组有序的列 3.大致可看成共享同一个index的Series集合 ...

  3. IntelliJ IDEA 2019.2破解

    IntelliJ IDEA 2019.2破解 我是参考这个激活的,使用的激活码的方式,需要在百度云盘下载压缩包 https://zhile.io/2018/08/25/jetbrains-licens ...

  4. Linux内核调试的方式以及工具集锦

    原文:https://blog.csdn.net/gatieme/article/details/68948080 CSDN GitHubLinux内核调试的方式以及工具集锦 LDD-LinuxDev ...

  5. SpringMVC_原理(转)

    在整个Spring MVC框架中,DispatcherServlet处于核心位置,它负责协调和组织不同组件完成请求处理并返回响应的工作.具体流程为:1)客户端发送http请求,web应用服务器接收到这 ...

  6. LeetCode 1043. Partition Array for Maximum Sum

    原题链接在这里:https://leetcode.com/problems/partition-array-for-maximum-sum/ 题目: Given an integer array A, ...

  7. Centos 不重启 修改ulimit参数

    1. 查看limits.conf文件 cat /etc/security/limits.conf 2. 打开编辑limits.conf文件 sudo vim /etc/security/limits. ...

  8. THUWC2020 划船记

    PS:THUWC2020在2019年 Day 1 考场外的太懒了不写了. 三题题目大意: T1: T2: 给定一个\(n(\leq 10^5)\)个结点的有向图,每条边有个limit,表示经过这条边l ...

  9. 洛谷P3509 Frog

    题目 首先分析数据范围发现m很大,所以线性做法肯定不行,因此考虑倍增,即预处理出每个点跳1次后的位置.然后只用两个数组类似于快速幂,推出每个点跳m次后的位置. 预处理离每个点第k小的点,可以用长度为k ...

  10. 前后端通信—CORS(支持跨域)

    根据前端跨域的那些事这篇文章中的跨域的理解这一块,我们重新创建两个服务,第一个服务使用了test.html const http = require('http') const fs = requir ...