关闭

2017广西邀请赛CS Course(&|^位运算模拟)

标签: 位运算广西邀请赛
1141人阅读 评论(0) 收藏 举报
分类:

中石油提交网址:http://exam.upc.edu.cn/problem.php?id=4334

4334: CS Course

时间限制: 2 Sec  内存限制: 512 MB
提交: 37  解决: 13
[提交][状态][讨论版]

题目描述

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.

输入

There are no more than 15 test cases.
Each test case begins with two positive integers n(2 ≤ n ≤ 105) and p(2 ≤ p ≤ 105) in a line, indicate the number of positive integers and the number of queries.
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].

输出

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.

样例输入

3 3
1 1 1
1
2
3

样例输出

1 1 0
1 1 0
1 1 0

【代码】:

#include <stdio.h>
#include <string.h>  
#include <algorithm> 
#define mset(a,i) memset(a,i,sizeof(a))
#define S1(n)     scanf("%d",&n)
#define S2(n,m)   scanf("%d%d",&n,&m)
using namespace std;
typedef long long ll;
const int MAX=1e6+5;
int a[MAX],b[MAX];
int n,m, And,Or,Xor;
int main()
{
	while(~S2(n,m))
	{
		mset(b,0);
		Xor=0,And=0xffffffff,Or=0;
		for(int i=1;i<=n;i++)
		{
			int x;S1(x);
			a[i]=x;
			And&=x;
			Or|=x;
			Xor^=x;
			for(int j=0;x;j++,x>>=1)
				b[j]+=x%2;
		}
		while(m--)
		{
			int q;S1(q);q=a[q];
			int A=And,O=Or,X=Xor;
			X=X^q;
			for(int j=0;j<=30;j++,q>>=1)
			{
				if(b[j]==n-1&&q%2==0)A+=(1<<j);
				if(b[j]==1  &&q%2   )O-=(1<<j);
			}
			printf("%d %d %d\n",A,O,X);
		}
	}
}


0
0
查看评论

广西2017邀请赛 Problem E CS Course

问题 E: CS Course Little A has come to college and majored in Computer and Science. Today he has learned bit-operations in Algorithm Lessons, and he got...
  • MM__1997
  • MM__1997
  • 2017-08-29 22:32
  • 853

2017ACM-ICPC全国邀请赛(广西)

本学期有幸参加的第二场邀请赛,这次本来是抱着旅游心态,带带两个小弟出去见见世面的。没想到距离银还差辣么点。 ======================流水账======================= 一大早起床赶高铁,蜜汁一只眼镜戴了20分钟戴不进,临时临急出门之后在车上秒戴进了。。。(看来...
  • QuanQqqqq
  • QuanQqqqq
  • 2017-09-01 00:49
  • 896

广西 2017 邀请赛 CS Course

题目描述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 ...
  • upc1607020107
  • upc1607020107
  • 2017-08-31 02:06
  • 70

【2017广西邀请赛】hdu 6186 CS Course

Problem Description Little A has come to college and majored in Computer and Science. Today he has learned bit-operations in Algorithm Lessons, ...
  • zchahaha
  • zchahaha
  • 2017-09-06 11:52
  • 172

2017年广西邀请赛总结

第一次参加线下赛,还是挺激动的。比赛已经过去好多天了,想想还是写个总结纪念一下第一次参见线下赛吧。通过这次比赛再次证明了,我真的很菜很菜。。。赛前想着至少要写完签到题,没想到最后签到题也没写完。 这次比赛之前说没有热身赛只有试机什么的,所以去的就晚一点,后来好像又有题目了,不过我们那里并没见,就开...
  • acm_du
  • acm_du
  • 2017-08-31 20:51
  • 234

广西2017邀请赛 E: CS Course &,|,^ 运算

E: CS Course 时间限制: 2 Sec  内存限制: 512 MB 提交: 79  解决: 21 [提交][状态][讨论版] 题目描述 Little A has come to college...
  • sizaif
  • sizaif
  • 2017-09-03 11:09
  • 575

HDU 6186 && 2017广西邀请赛:CS Course

题意: n个数,m次查询,每次给出一个p,求出除了第p个数以外其它所有数的且和,或和,异或和 统计下每个二进制位1的数量,例如z[5] = x表示有x个数第5个二进制位为1 之后每次查询只要check一下z[]就好 #include #include int a[100005...
  • Jaihk662
  • Jaihk662
  • 2017-08-31 17:12
  • 216

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

这是在厚林工作室4个人打的一场骚呢两年没回去了拿lzy的号打,打的被老刘查水表了01枚举kkk^k,k≤15k \leq 15。 看到我的TT就知道我是怎么wa的了。。#include <bits/stdc++.h>using namespace std; typedef long l...
  • cww97
  • cww97
  • 2017-08-31 21:16
  • 1112

HDU6186 | 2017广西邀请赛 CS Course (前缀和后缀)

CS Course Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 430 ...
  • i1020
  • i1020
  • 2017-09-02 21:37
  • 287

CS Course (广西2017邀请赛) 用线段树区间查询

4334: CS Course 时间限制: 2 Sec  内存限制: 512 MB 题目描述 Little A has come to college and majored in Computer and Science. Today he has learned bit-ope...
  • Sunshine_victory
  • Sunshine_victory
  • 2017-08-28 21:43
  • 102
    个人资料
    • 访问:103697次
    • 积分:3019
    • 等级:
    • 排名:第13770名
    • 原创:197篇
    • 转载:9篇
    • 译文:0篇
    • 评论:33条
    博客专栏
    最新评论