2017 ICPC 广西邀请赛1005 CS Course
CS Course
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
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.
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].
1 1 1
1
2
3
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的更多相关文章
- 2017ACM/ICPC广西邀请赛 1005 CS Course
CS Course Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- 2017 ICPC 广西邀请赛1004 Covering
Covering Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 2017ACM/ICPC广西邀请赛-重现赛1005 CS course
2017-08-31 16:19:30 writer:pprp 这道题快要卡死我了,队友已经告诉我思路了,但是做题速度很缓慢,很费力,想必是因为之前 的训练都是面向题解编程的缘故吧,以后不能这样了,另 ...
- 2017ACM/ICPC广西邀请赛 CS Course
题意:删除指定数字,求剩下数字的与或非值 解法:保存一下前缀和后缀 #include <iostream> #include <stdio.h> #include <ve ...
- 2017 ACM/ICPC 广西邀请赛 题解
题目链接 Problems HDOJ上的题目顺序可能和现场比赛的题目顺序不一样, 我这里的是按照HDOJ的题目顺序来写的. Problem 1001 签到 #include <bits/std ...
- 2017ICPC/广西邀请赛1005(水)HDU6186
CS Course Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- 2017ACM/ICPC广西邀请赛-重现赛
HDU 6188 Duizi and Shunzi 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 思路: 签到题,以前写的. 实现代码: #inc ...
- 2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)
上一场CF打到心态爆炸,这几天也没啥想干的 A Math Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/3 ...
- 2017ACM/ICPC广西邀请赛-重现赛 1007.Duizi and Shunzi
Problem Description Nike likes playing cards and makes a problem of it. Now give you n integers, ai( ...
随机推荐
- 如何解决Python.h:No such file or directory
安装python2.7对应的dev sudo apt-get install python-dev 安装python3.6对应的dev sudo apt-get install python3-dev
- Delphi系列书籍pdf 118本 网友吐血整理
第一步:进入官网首页http://bulo.hujiang.com/home/ 第二部:home/替换u/779988/diary/627936/ 来自沪江部落
- POJ-1273-Drainage Ditches(网络流之最大流)
Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This ...
- hdu2222 ac自动机入门
Keywords Search Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- bzoj3713 [PA2014]Iloczyn|暴力(模拟)
斐波那契数列的定义为:k=0或1时,F[k]=k:k>1时,F[k]=F[k-1]+F[k-2].数列的开头几项为0,1,1,2,3,5,8,13,21,34,55,-你的任务是判断给定的数字能 ...
- 决策树模型组合之随机森林与GBDT
版权声明: 本文由LeftNotEasy发布于http://leftnoteasy.cnblogs.com, 本文可以被全部的转载或者部分使用,但请注明出处,如果有问题,请联系wheeleast@gm ...
- 在ubuntu16.04中安装apache2+modsecurity以及自定义WAF规则详解
一.Modsecurity规则语法示例 SecRule是ModSecurity主要的指令,用于创建安全规则.其基本语法如下: SecRule VARIABLES OPERATOR [ACTIONS] ...
- IOS系统配置FFMEPG
在FFMPEG的官网上可以找到标准的配置文档...http://ffmpeg.org/trac/ffmpeg/wiki/MacOSXCompilationGuide 在开始前确保安装了XCODE而且也 ...
- npm install 时--save-dev和--save的区别
package.json中两个字段含义简介 一直在使用npm包管理器,对于npm install module --save-dev 和 npm install module --save这两个的区别 ...
- oracle 表空间不足解决办法
问题:在对某一表空间进行新建表的时候,出现ora-01658的错误. create 语句: create table OA_ORGCONFIG( OAOC_UNID INTEGER not ...