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( ...
随机推荐
- CDS测试框架介绍:如何为ABAP CDS Entities写测试
动机 现在大家都知道单元测试对我们代码的好处.并且我们都承认它是开发过程中不可或缺的一部分.但是在把代码切换到数据库的模式下的时候,我们被粗暴地打回了软件测试的黑暗年代...我们现在面临着逻辑下推到A ...
- Azure SQL Database (24) 使用新管理界面,创建跨数据中心标准地域复制(Standard Geo-Replication)
<Windows Azure Platform 系列文章目录> 文本是对:SQL Azure (17) SQL Azure V12 - 跨数据中心标准地域复制(Standard Geo-R ...
- 在 macOS High Sierra 10.13 搭建 PHP 开发环境
2017 年 9 月 26 日,苹果公司正式发布了新一代 macOS,版本为 High Sierra (11.13). macOS High Sierra 预装了 Ruby(2.3.3).PHP(7. ...
- IIS充当代理转发请求到Kestrel
接着上篇博文为ASP.NetCore程序启用SSL的code,这篇将介绍如何用IIS充当反向代理的角色转发请求到Kestrel服务器 与ASP.NET不同,ASP.netCore使用的是自托管web服 ...
- pmap 命令详解
通过查看帮助,返回了如下信息: Usage: pmap [options] pid [pid ...] Options: -x, --extended show detai ...
- LInux ugo权限详解
Linux 中的用户和组是用来控制使用者或者进程可以或者不可以使用哪些资源和硬件,是Linux权限控制最基本的方式. 用户和组可以看一下上一章的部分,先来看一下权限. 一.权限概览 在Linux下,使 ...
- Spring3.2不支持jdk8
解决方案: http://stackoverflow.com/questions/24128045/spring-context-initialization-failed-with-java-lan ...
- Java连接数据库完整代码 查找和插入
package test; import java.io.InputStream; import java.sql.Connection; import java.sql.DriverManager; ...
- Elasticsearch 数据搜索
ES即简单又复杂,你可以快速的实现全文检索,又需要了解复杂的REST API.本篇就通过一些简单的搜索命令,帮助你理解ES的相关应用.虽然不能让你理解ES的原理设计,但是可以帮助你理解ES,探寻更多的 ...
- mvc的filter
如果想要记录ajax的请求和输出信息.内部发生异常记录日志.需要登录认证.需要权限判断:那mvc的各种filter可以帮助你实现你想要的.Mvc框架支持5种不同类型的过滤器:我会按照执行顺序进行简单的 ...