CS Course

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 112    Accepted Submission(s): 66

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
 

Source

 
 //2017-08-31
#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 = ;
int arr[N];
struct Node{
int l, r, OR, XOR, AND;
}st[N<<]; 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+, 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 == )return st[id].OR;
if(op == )return st[id].XOR;
if(op == )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 == )return query(lson, l, mid, op) | query(rson, mid+, r, op);
if(op == )return query(lson, l, mid, op) ^ query(rson, mid+, r, op);
if(op == )return query(lson, l, mid, op) & query(rson, mid+, r, op);
}
} int main()
{
int n, q;
while(scanf("%d%d", &n, &q)!=EOF)
{
for(int i = ; i <= n; i++)
scanf("%d", &arr[i]);
build(, , n);
int p;
while(q--){
scanf("%d", &p);
if(p == )
printf("%d %d %d\n", query(, , n, ), query(, , n, ), query(, , n, ));
else if(p == n)
printf("%d %d %d\n", query(, , n-, ), query(, , n-, ), query(, , n-, ));
else
printf("%d %d %d\n", query(, , p-, )&query(, p+, n, ), query(, , p-, )|query(, p+, n, ), query(, , p-, )^query(, p+, n, ));
}
} return ;
}

HDU6186(线段树)的更多相关文章

  1. bzoj3932--可持久化线段树

    题目大意: 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的 任务用三元组(Si,Ei,Pi)描述,(Si,Ei,Pi)表示任务从第Si秒开始,在第 ...

  2. codevs 1082 线段树练习 3(区间维护)

    codevs 1082 线段树练习 3  时间限制: 3 s  空间限制: 128000 KB  题目等级 : 大师 Master 题目描述 Description 给你N个数,有两种操作: 1:给区 ...

  3. codevs 1576 最长上升子序列的线段树优化

    题目:codevs 1576 最长严格上升子序列 链接:http://codevs.cn/problem/1576/ 优化的地方是 1到i-1 中最大的 f[j]值,并且A[j]<A[i] .根 ...

  4. codevs 1080 线段树点修改

    先来介绍一下线段树. 线段树是一个把线段,或者说一个区间储存在二叉树中.如图所示的就是一棵线段树,它维护一个区间的和. 蓝色数字的是线段树的节点在数组中的位置,它表示的区间已经在图上标出,它的值就是这 ...

  5. codevs 1082 线段树区间求和

    codevs 1082 线段树练习3 链接:http://codevs.cn/problem/1082/ sumv是维护求和的线段树,addv是标记这歌节点所在区间还需要加上的值. 我的线段树写法在运 ...

  6. PYOJ 44. 【HNSDFZ2016 #6】可持久化线段树

    #44. [HNSDFZ2016 #6]可持久化线段树 统计 描述 提交 自定义测试 题目描述 现有一序列 AA.您需要写一棵可持久化线段树,以实现如下操作: A v p x:对于版本v的序列,给 A ...

  7. CF719E(线段树+矩阵快速幂)

    题意:给你一个数列a,a[i]表示斐波那契数列的下标为a[i],求区间对应斐波那契数列数字的和,还要求能够维护对区间内所有下标加d的操作 分析:线段树 线段树的每个节点表示(f[i],f[i-1])这 ...

  8. 【BZOJ-3779】重组病毒 LinkCutTree + 线段树 + DFS序

    3779: 重组病毒 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 224  Solved: 95[Submit][Status][Discuss] ...

  9. 【BZOJ-3673&3674】可持久化并查集 可持久化线段树 + 并查集

    3673: 可持久化并查集 by zky Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 1878  Solved: 846[Submit][Status ...

随机推荐

  1. 抓取分析网页批量下载评书(3)之批量下载mp3

         本系列目录:    <1.搜索有声小说>    <2.分析详细页地址>     <3.批量下载mp3>      本篇是大结局,看过前两篇的放心吧,不会有 ...

  2. Shell - 简明Shell入门05 - 条件语句(Case)

    示例脚本及注释 #!/bin/bash var=$1 # 将脚本的第一个参数赋值给变量var case $var in right) echo "Right!";; wrong) ...

  3. .gitignore总结

    git进行管理时,.gitignore是必不可少的,可以指定不需要提交到仓库的资源.最好在git init之后就创建 .gitignore文件,这是个好习惯,常用的配置及说明如下:

  4. TortoiseSVN切换更改登录账号密码

    TortoiseSVN切换更改登录账号密码 方法: 在TortoiseSVN的设置对话框中,选择“已保存数据”,在“认证数据”那一行点击“清除”按钮,清楚保存的认证数据,再检出的时候就会重新跳出用户名 ...

  5. ES代码总结2

    本文部分转载于: http://www.cnblogs.com/luxiaoxun/p/4869509.html ElasticSearch的基本用法与集群搭建  一.简介 ElasticSearch ...

  6. idea自己用得到的命令

    1.注释 Ctrl + / 单行注释 . 取消注释 Ctrl + Shift + / 多行注释 .取消注释 2.查找 Ctrl + N 通过输入类名打开类(标准说法是查找类文件) Ctrl + Shi ...

  7. atexit()使用

    mian()主函数执行完毕后,是否可能会再执行一段代码?如果需要加入一段代码在mian退出后执行的代码,可以使用atexit()函数注册一个函数,代码如下: #include <iostream ...

  8. 【Canal源码分析】TableMetaTSDB

    这是Canal在新版本引入的一个内容,主要是为了解决由于历史的DDL导致表结构与现有表结构不一致,导致的同步失败的问题.采用的是Druid和Fastsql,来记录表结构到DB中,如果需要进行回滚时,得 ...

  9. Android四大组件之---activity生命周期详解

    废话不多说, 先来一张Google提供的一张经典的生命周期流程图: 有的朋友可能看英文的有点费劲,再提供一张中文版的  O(∩_∩)O 相信已经很多人对这张图再熟悉不过了,下面笔者按照自己的理解并结合 ...

  10. 使用XHProf分析PHP性能瓶颈(一)

    安装xhprof扩展 wget http://pecl.php.net/get/xhprof-0.9.4.tgz tar zxf xhprof-0.9.4.tgz cd xhprof-0.9.4/ex ...