【HDU - 6186】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 as homework. 

Here is the problem: 

You are giving n non-negative integers a1,a2,⋯,ana1,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 apap. 

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≤1052≤n,q≤105 

Then n non-negative integers a1,a2,⋯,ana1,a2,⋯,an follows in a line, 0≤ai≤1090≤ai≤109 for each i in range[1,n]. 

After that there are q positive integers p1,p2,⋯,pqp1,p2,⋯,pqin q lines, 1≤pi≤n1≤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 apap in a line. 

Sample Input

3 3
1 1 1
1
2
3

Sample Output

1 1 0
1 1 0
1 1 0

题目大意:

题意:给定n 个数和 q 个查询,qi 为查询数,求去掉下标为qi 的元素后其他元素 and , or , xor的结果。

解题报告:

这题也可以用线段树nlogn搞或者直接处理前缀后缀然后on搞(因为没有修改嘛)然后也可以按位统计然后nlogn乱搞。。

但是前者没法做带更新的,后者可以。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
int cnt[44];
ll a[MAX];
int n,q,p;
int main() 
{while(~scanf("%d%d",&n,&q)) {memset(cnt,0,sizeof cnt);ll Xor = 0;for(int i = 1; i<=n; i++) scanf("%lld",a+i),Xor ^= a[i];for(int i = 1; i<=n; i++) {for(int j = 0; j<33; j++) {cnt[j] += (a[i]>>j)&1;}}while(q--) {scanf("%d",&p);ll And=0,Or=0,X;ll tar = a[p];X = Xor^tar;for(int j = 0; j<33; j++) {ll tmp = (tar>>j)&1;if(cnt[j]-tmp>0) Or |= (1<<j);if(cnt[j]-tmp == n-1) And |= (1<<j);}printf("%lld %lld %lld\n",And,Or,X);}	}return 0 ;
}

 

AC代码2:

#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
#define mid ((st[id].l+st[id].r)>>1)
#define lson (id<<1)
#define rson ((id<<1)|1)using namespace std;const int N = 150000;
int arr[N];
struct Node{int l, r, OR, XOR, AND;
}st[N<<3];void build(int id, int l, int r)
{st[id].l = l; st[id].r = r;if(l == r){st[id].OR = arr[l];st[id].AND = arr[l];st[id].XOR = arr[l];return;}build(lson, l, mid);build(rson, mid+1, r);st[id].OR = st[lson].OR | st[rson].OR;st[id].XOR = st[lson].XOR ^ st[rson].XOR;st[id].AND = st[lson].AND & st[rson].AND;
}int query(int id, int l, int r, int op){if(st[id].l == l && st[id].r == r){if(op == 1)return st[id].OR;if(op == 2)return st[id].XOR;if(op == 3)return st[id].AND;}if(l > mid)return query(rson, l, r, op);else if(r <= mid)return query(lson, l, r, op);else{if(op == 1)return query(lson, l, mid, op) | query(rson, mid+1, r, op);if(op == 2)return query(lson, l, mid, op) ^ query(rson, mid+1, r, op);if(op == 3)return query(lson, l, mid, op) & query(rson, mid+1, r, op);} 
}int main()
{int n, q;while(scanf("%d%d", &n, &q)!=EOF){for(int i = 1; i <= n; i++)scanf("%d", &arr[i]);build(1, 1, n);int p;while(q--){scanf("%d", &p);if(p == 1)printf("%d %d %d\n", query(1, 2, n, 3), query(1, 2, n, 1), query(1, 2, n, 2));else if(p == n)printf("%d %d %d\n", query(1, 1, n-1, 3), query(1, 1, n-1, 1), query(1, 1, n-1, 2));else    printf("%d %d %d\n", query(1, 1, p-1, 3)&query(1, p+1, n, 3), query(1, 1, p-1, 1)|query(1, p+1, n, 1), query(1, 1, p-1, 2)^query(1, p+1, n, 2));}}return 0;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440459.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

mysql不能存字母,使用不常見的字母/符號時,MySql數據庫不能正確存儲數據

I have a simple form that sends (via php) some variables to a mySql database.我有一個簡單的表單,通過PHP發送一些變量到mySql數據庫。The problem is that its focused to Portuguese audience, and we use several unusual letters, like "" and ""…

【HDU - 6184】Counting Stars(三元环计数,二分,优化暴力,O(m*sqrt(m)),图论)

题干&#xff1a; Little A is an astronomy lover, and he has found that the sky was so beautiful! So he is counting stars now! There are n stars in the sky, and little A has connected them by m non-directional edges. It is guranteed that no edges connec…

php 取oracle图片,在PHP中将图片存放ORACLE中_php

我这里提供一个用php操纵blob字段的例子给你&#xff0c;希望能有所帮助&#xff01;这个例子是把用户上传的图片文件存放到BLOB中。假设有一个表&#xff0c;结构如下&#xff1a;CREATE TABLE PICTURES (ID NUMBER,http://www.gaodaima.com/44856.html在PHP中将图片存放oracl…

【HDU - 6183】Color it(CDQ分治 或 动态开点线段树)

题干&#xff1a; Do you like painting? Little D doesnt like painting, especially messy color paintings. Now Little B is painting. To prevent him from drawing messy painting, Little D asks you to write a program to maintain following operations. The speci…

php create()方法,ThinkPHP中create()方法自动验证实例

ThinkPHP中create()方法自动验证实例2020-06-16 04:24:32自动验证是ThinkPHP模型层提供的一种数据验证方法&#xff0c;可以在使用create创建数据对象的时候自动进行数据验证。原理&#xff1a;create()方法收集表单($_POST)信息并返回&#xff0c;同时触发表单自动验证&#x…

【蓝桥杯官网试题 - 历届试题】格子刷油漆(dp)

题干&#xff1a; 问题描述 X国的一段古城墙的顶端可以看成 2*N个格子组成的矩形&#xff08;如下图所示&#xff09;&#xff0c;现需要把这些格子刷上保护漆。   你可以从任意一个格子刷起&#xff0c;刷完一格&#xff0c;可以移动到和它相邻的格子&#xff08;对角相邻也…

php 解析 ini文件,php解析.ini文件

1.myphp.ini文件autostart false font_size 12font_color red$string[access] 进入;$string[accesshelp] 进入帮助;$string[accesskey] 进入验证 {$a};$string[accessstatement] 进入声明;$string[activitynext] 下一个活动;$string[activityprev] 前一个活动;$string…

【CSU - 1004】Xi and Bo(并查集,裸题)

题干&#xff1a; Bo has been in Changsha for four years. However he spends most of his time staying his small dormitory. One day he decides to get out of the dormitory and see the beautiful city. So he asks to Xi to know whether he can get to another bus …

oracle软件静默安装程序,【oracle】静默安装 oracle 11gr2

【序言】oracle 提供了静默安装方法在不适用图形界面的情况下安装 oracle 软件 ,创建db,配置netca,快速完成oracle 的部署。在以下情形中可以使用静默安装a OUI 的 GUI 界面远程交互比较慢 .b 数据库服务器无法使用图形界面访问.c 批量部署oracle (标准环境统一情况下可以使用o…

【2050 Programming Competition - 2050 一万人码 】非官方部分题解(HDU)

1001 开场白 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 12147 Accepted Submission(s): 3502 Problem Description 来自世界各地的年青人在 https://2050.org.cn 握手团聚&#xff0c; 他们是航空…

oracle数据库建表视频,Oracle数据库的创建表全

CREATE TABLE "库名"."表名" ("FEE_ID" VARCHAR2(10 BYTE) constraint ABS_FEE_ID primary key,--主键&#xff0c;必须要有序列"BANK_GROUP_ID" VARCHAR2(5 BYTE),"ABS_PRODUCT_ID" VARCHAR2(30 BYTE))TABLESPACE "表…

oracle的脚本语言是什么意思,Oracle中的sql脚本语言中的循环语句介绍

--sql脚本语言的循环介绍&#xff1a;--1.goto循环点。declarex number;beginx:0;--变量初始化&#xff1b;<>--设置循环点。x:x1;dbms_output.put_line(x);--循环体if x<9 then --进入循环的条件。goto repeat_loop; --用goto关键字引导进入循环。end i…

【poj题集整理】【存下来并不会看】

主要是整理起来自己用的。网上有多个版本。 初级: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. (5)构造法.(poj3295) (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996) 二.图算…

oracle排名怎么去除空值影响,Oracle排序中null值处理方法讲解

1、缺省处理oracle在order by 时缺省认为null是最大值&#xff0c;所以如果是asc升序则排在最后&#xff0c;desc降序则排在最前2、使用nvl函数nvl函数可以将输入参数为空时转换为一特定值&#xff0c;如nvl(employee_name,’张三’)表示当employee_name为空时则返回’张三’&a…

【ZOJ - 3870】Team Formation(异或,思维)

题干&#xff1a; For an upcoming programming contest, Edward, the headmaster of Marjar University, is forming a two-man team from N students of his university. Edward knows the skill level of each student. He has found that if two students with skill lev…

oracle dump enq hw,经典故障分析 - ASSM引发的索引争用与 enq HW -contentio

作者介绍&#xff1a;孙加鹏 云和恩墨技术顾问六年Oracle技术顾问经验&#xff0c;所服务的行业包括电信运营商、金融业、制造业等。擅长Oracle的故障诊断、高可用架构、升级迁移等。目前主要服务于上海金融类客户。1故障概述2017年07月24日11:58左右&#xff0c;客户核心数据库…

【ZOJ - 3946】Highway Project(最短路子图,维护双权值,贪心,最小树形图)

题干&#xff1a; Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cities from the capital as fast as possible. Thus, he proposed the highway project. The Marjar Empire has N cities (including…

oracle 主键约束复制,Oracle主键及约束

Oracle主键Primary Key包含非空约束及唯一约束。添加主键的语句alter table table_nameadd constraint cons_name primary key(col_name);查看主键是否被创建成功select dbms_metadata.get_ddl(‘OBJECT_TYPE‘,‘NAME‘,‘SCHEMA‘) from dual;OBJECT_TYPE (TABLE,PARTITION,I…

【ZOJ - 3956】Course Selection System(01背包)

题干&#xff1a; There are n courses in the course selection system of Marjar University. The i-th course is described by two values: happiness Hi and credit Ci. If a student selects m courses x1, x2, ..., xm, then his comfort level of the semester can be…

oracle 账户 锁定 密码忘记了,Oracle System密码忘记 密码修改、删除账号锁定lock

运行cmd命令行录入 sqlplus /nolog 无用户名登录conn /as sysdba 连接到数据本地数据alter user system identified by password; 修改System 密码 为passwordD:\oracle\ora92\bin>sqlplus /nologSQL*Plus: Release 9.2.0.1.0 - Production on 星期四 8月 16 11:32:22 …