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,⋯,pqin 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

/*
* @Author: Administrator
* @Date: 2017-08-31 17:13:07
* @Last Modified by: Administrator
* @Last Modified time: 2017-08-31 17:45:05
*/
/*
题意:给你n个数,然后m次查询,每次给你一个q ,问你除去a[q]之后所有数的 and or xor 思路:xor可以直接得出,and 和 or 只需要判断一下每位1的个数 感悟:上学期我以后学分选完了,结果一看XK 的都没选,这学期课挺多的...今下午没打比赛
在教室想了一下1005和1004下了课就过来实现了,没想到1A了,看来我还是适合紧张的学习
环境...
*/
#include <bits/stdc++.h> #define MAXN 100005
#define LL long long
using namespace std; int n,m;
LL a[MAXN];
int q;
int vis[];//统计每位的1的个数
LL res1,res2,res3;//未去除的最后结果
LL pos;//指针
LL cur1,cur2,cur3;//最后结果
LL cnt;
int cnt1[],cnt2[];//最后结果的二进制,xor操作可O(1)算出来所以不用保存 void cal(LL x){//统计每位上1的个数
for(int i=;i<;i++){
if(x%==){
vis[i]++;
}
x/=;
}
} void po(LL x,int sw){
for(int i=;i<;i++){
switch(sw){
case :
cnt1[i]=x%;
break;
case :
cnt2[i]=x%;
break;
}
x/=;
}
} inline void init(){
memset(vis,,sizeof vis);
cur1=;
cur2=;
cur3=;
} int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF){
init();
for(int i=;i<n;i++){
scanf("%lld",&a[i]);
cal(a[i]);
if(i==){
res1=a[i],res2=a[i],res3=a[i];
}else{
res1&=a[i];
res2|=a[i];
res3^=a[i];
}
}
//将结果处理成二进制
po(res1,);po(res2,); for(int i=;i<m;i++){ cur1=;
cur2=;
cur3=; scanf("%d",&q); //处理and操作
pos=a[q-];
cnt=;
for(int i=;i<;i++){
if(pos%==){
if(vis[i]==n-){
cur1+=cnt;
}
}else{
if(cnt1[i]==){
cur1+=cnt;
}
}
pos/=;
cnt*=;
} //处理or操作
pos=a[q-];
cnt=;
for(int i=;i<;i++){
if(pos%==){
if(vis[i]!=){
cur2+=cnt;
}
}else{
if(cnt2[i]==){
cur2+=cnt;
}
}
pos/=;
cnt*=;
}
//处理xor操作
cur3=res3^a[q-];
printf("%lld %lld %lld\n",cur1,cur2,cur3);
}
}
return ;
}

2017 ICPC 广西邀请赛1005 CS Course的更多相关文章

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

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

  2. 2017 ICPC 广西邀请赛1004 Covering

    Covering Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

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

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

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

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

  5. 2017 ACM/ICPC 广西邀请赛 题解

    题目链接  Problems HDOJ上的题目顺序可能和现场比赛的题目顺序不一样, 我这里的是按照HDOJ的题目顺序来写的. Problem 1001 签到 #include <bits/std ...

  6. 2017ICPC/广西邀请赛1005(水)HDU6186

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

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

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

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

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

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

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

随机推荐

  1. String类的构造方法(2)

    写了常见的几个而已. 1:new 一个String类的时候系统会自动传一个空构造 public String(); 注意: 当对象初始化是 null时 和 对象是 "" 时,两者是 ...

  2. SpringAop详解

    近几天学习了一下SpringAop在网上找了一些资料,此链接为原文链接http://www.cnblogs.com/xrq730/p/4919025.html AOP AOP(Aspect Orien ...

  3. 进入css3动画世界(一)

    其实我做css3动画也没有多久,这篇文章目标人群是css3动画的新手,不喜勿喷. 分类 目前我接触到的css3动画有2类:一种是transition的,另一种是@keyframes的. 两者的区别就是 ...

  4. U方法

    U方法用于完成对URL地址的组装,特点在于可以自动根据当前的URL模式和设置生成对应的URL地址,格式为:U('地址','参数','伪静态','是否跳转','显示域名');在模板中使用U方法而不是固定 ...

  5. Python打印乘法口诀表

    思路:第一行:1*1,第二行:1*2.,2*2,第三行:1*3,2*3,3*3-- 最后一行:1*9,2*9,3*9,-9*9,以此类推,可以设2个数:i,j:让 i 从1循环到9,让 j 从1到小于 ...

  6. SpringMVC框架(一)

    SpringMVC最核心:DispatcherServlet SpringMVC环境搭建: 结构: 过程: 1.导包 2.声明SpringMVC核心Servlet:org.springframewor ...

  7. MongoDB数据库的安装、配置和使用

    1.下载安装包   wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.7.tgz 2.解压安装包   tar -zxf mo ...

  8. [js插件开发教程]一步步开发一个可以定制配置的隔行变色小插件

    隔行变色功能,不用js,直接用css伪类就可以做,这个实例可以作为js插件开发很好的入门级实例.本文实现的隔行变色包括以下功能: 1,支持2种常用结构共存( div元素 和 表格类型 ) 2,一个页面 ...

  9. Jquery cookie操作示例,写入cookie,读取cookie,删除cookie

    <html> <head> <meta name="viewport" content="width=device-width" ...

  10. Linux目录结构详解(一)

    Linux目录结构,在逻辑上所有目录只有一个顶点,即/(根目录),是所有目录的起点.根下面类似于一个倒挂着的树的结构. Linux目录按照类别组织: 应用程序 /usr/bin 数据文件,帮助/usr ...