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. 关于sql语句引发的404错误

    今天分享个小问题,也是今天在项目中遇到的,希望对遇到相关问题的朋友有所帮助. 使用工具:(相关的) mybatis,spring-mvc,mysql 问题原因: 我在mybatis的mapper文件中 ...

  2. cocos2dx 播放gif

    起因 或许有人会说,cocos2dx中直接帧动画就行了用什么GIF. 起因是为游戏内部要用到第三方平台的头像,而第三方平台的头像大多都是用到Gif,所以才会有了这个需求 过程 查了各种文档都没找到.但 ...

  3. 认识:ThinkPHP的编译缓存文件~runtime.php

    1.定义单入口文件(index.php) 在单入口index.php中不定义这两项时,会生成编译缓存文件~runtime.php define('RUNTIME_PATH','./App/Temp/' ...

  4. mybatis错误——java.io.IOException: Could not find resource com/xxx/xxxMapper.xml

    在学习Mybatis的时候,参考网上的教程进行简单demo的搭建,配置的没有问题,然后出现了下面的错误! Exception in thread "main" java.lang. ...

  5. httpd网页身份认证

    html { font-family: sans-serif } body { margin: 0 } article,aside,details,figcaption,figure,footer,h ...

  6. ZOJ2345Gold Coins 简单分块

    昨天做过一样的题: 平方和公式:n*(n+1)*(2n+1) #include<cstdio> #include<cstdlib> #include<iostream&g ...

  7. C#基础之转换

    C#中一共有两种转换方式,隐式转换和显示转换 隐式转换:就是不需要声明就能进行的转换,通俗来说就是小范围内的数据类型转大范围数据类型 显示转换:就是通常说的强制转换,需要在代码中写明要的数据类型.通俗 ...

  8. git 分支改名

    给一个git分支改名的方法很简单 如果对于分支不是当前分支,可以使用下面代码: git branch -m 原名 新 如果是当前,那么可以使用加上新名字 git branch -m 原名 参见: ht ...

  9. 什么是UUID?

    1.定义 UUID含义是通用唯一识别码 (Universally Unique Identifier),这 是一个软件建构的标准,也是被开源软件基金会 (Open Software Foundatio ...

  10. 基于HTML5的WebGL实现json和echarts图表展现在同一个界面

    突然有个想法,如果能把一些用到不同的知识点放到同一个界面上,并且放到一个盒子里,这样我如果要看什么东西就可以很直接显示出来,而且这个盒子一定要能打开.我用HT实现了我的想法,代码一百多行,这么少的代码 ...