线段树!!1A

代码如下:

 #include<iostream>
#include<cstdio>
#define lson i<<1
#define rson i<<1|1
#define MAX 140000
#define ll __int64
using namespace std;
ll a[MAX],s;
struct tree
{
int l,r;
ll res;
bool flag;
}T[*MAX];
//奇数OR,偶数XOR
void built(int i,int l,int r,bool f)
{
T[i].l=l;
T[i].r=r;
T[i].flag=f;
if(l==r){
T[i].res=a[l];
return ;
}
int m=(l+r)>>;
built(lson,l,m,!f);
built(rson,m+,r,!f);
if(T[i].flag) T[i].res=T[lson].res|T[rson].res;
else T[i].res=T[lson].res^T[rson].res;
}
void update(int i,int d,ll p)
{
if(T[i].l==d&&T[i].r==d){
T[i].res=p;
return ;
}
int m=(T[i].l+T[i].r)>>;
if(d<=m) update(lson,d,p);
else if(d>m) update(rson,d,p);
if(T[i].flag) T[i].res=T[lson].res|T[rson].res;
else T[i].res=T[lson].res^T[rson].res;
}
int main()
{
int n,m,i,k;
while(scanf("%d%d",&n,&m)!=EOF){
for(i=;i<=(<<n);i++) scanf("%I64d",&a[i]);
built(,,(<<n),n&);
for(i=;i<m;i++){
scanf("%d %I64d",&k,&s);
update(,k,s);
printf("%I64d\n",T[].res);
}
}
return ;
}

CF 197 DIV2 Xenia and Bit Operations 线段树的更多相关文章

  1. codeforces 339C Xenia and Bit Operations(线段树水题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Xenia and Bit Operations Xenia the beginn ...

  2. CodeForces 339D Xenia and Bit Operations (线段树)

    题意:给定 2的 n 次方个数,对这些数两个两个的进行或运算,然后会减少一半的数,然后再进行异或运算,又少了一半,然后再进行或运算,再进行异或,不断重复,到最后只剩下一个数,要输出这个数,然后有 m ...

  3. [Codeforces Round #296 div2 D] Clique Problem 【线段树+DP】

    题目链接:CF - R296 - d2 - D 题目大意 一个特殊的图,一些数轴上的点,每个点有一个坐标 X,有一个权值 W,两点 (i, j) 之间有边当且仅当 |Xi - Xj| >= Wi ...

  4. CF 552(div 3) E Two Teams 线段树,模拟链表

    题目链接:http://codeforces.com/contest/1154/problem/E 题意:两个人轮流取最大值与旁边k个数,问最后这所有的数分别被谁给取走了 分析:看这道题一点思路都没有 ...

  5. HDU 6315 Naive Operations(线段树区间整除区间)

    Problem DescriptionIn a galaxy far, far away, there are two integer sequence a and b of length n.b i ...

  6. hdu Naive Operations 线段树

    题目大意 题目链接Naive Operations 题目大意: 区间加1(在a数组中) 区间求ai/bi的和 ai初值全部为0,bi给出,且为n的排列,多组数据(<=5),n,q<=1e5 ...

  7. 杭电多校第二场 hdu 6315 Naive Operations 线段树变形

    Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Other ...

  8. CF 666E Forensic Examination 【SAM 倍增 线段树合并】

    CF 666E Forensic Examination 题意: 给出一个串\(s\)和\(n\)个串\(t_i\),\(q\)次询问,每次询问串\(s\)的子串\(s[p_l:p_r]\)在串\(t ...

  9. CF #296 (Div. 1) A. Glass Carving 线段树

    A. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

随机推荐

  1. asp.net实现手机号码归属地查询,代码如下

    protected void Button1_Click(object sender, EventArgs e)        {            if (Regex.IsMatch(TextB ...

  2. C++ STL中Map的按Key排序和按Value排序

    map是用来存放<key, value>键值对的数据结构,可以很方便快速的根据key查到相应的value.假如存储学生和其成绩(假定不存在重名,当然可以对重名加以区 分),我们用map来进 ...

  3. SQL SERVER定时任务执行跟踪--供远程查看 [原创]

    一.背景 每次查需要优化的SQL都需要上外网,通过Profiler,报表或者DMV执行特定sql来查找,来回跑很麻烦,能不能在本地直接监控外网的好性能的SQL呢?方法是有的,我们可以通过把Profil ...

  4. Java实现Tire

    Trie,又称单词查找树或键树,是一种树形结构.典型应用是用于统计和排序大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计.它的优点是:最大限度地减少无谓的字符串比较,查询效率比 ...

  5. 20145129 《Java程序设计》第6周学习总结

    20145129 <Java程序设计>第6周学习总结 教材学习内容总结 InputStream与OutStream 串流设计的概念 输入串流代表对象为java.io.InputStream ...

  6. sqlserver 查看锁表,解锁

    查看被锁表: 代码如下 复制代码 select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableName ...

  7. 图片上传前的预览(PHP)

    1.先创建一个file表单域,我们需要用它来浏览本地文件.<form name="form1" id="form1" method="post& ...

  8. 装载:对CSS中的Position、Float属性的一些深入探讨

    对CSS中的Position.Float属性的一些深入探讨   对CSS中的Position.Float属性的一些深入探讨 对于Position.Float我们在平时使用上可以说是使用频率非常高的两个 ...

  9. sql records

    DROP TABLE IF EXISTS student; CREATE TABLE student ( id INT NOT NULL AUTO_INCREMENT, student_name ) ...

  10. [百度空间] [原] Empty base class optimization

    最近遇到了一个诡异的问题, 数组的数据不对, 最后发现是两个类型的大小不一样导致的. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...