线段树!!1A

代码如下:

  1. #include<iostream>
  2. #include<cstdio>
  3. #define lson i<<1
  4. #define rson i<<1|1
  5. #define MAX 140000
  6. #define ll __int64
  7. using namespace std;
  8. ll a[MAX],s;
  9. struct tree
  10. {
  11. int l,r;
  12. ll res;
  13. bool flag;
  14. }T[*MAX];
  15. //奇数OR,偶数XOR
  16. void built(int i,int l,int r,bool f)
  17. {
  18. T[i].l=l;
  19. T[i].r=r;
  20. T[i].flag=f;
  21. if(l==r){
  22. T[i].res=a[l];
  23. return ;
  24. }
  25. int m=(l+r)>>;
  26. built(lson,l,m,!f);
  27. built(rson,m+,r,!f);
  28. if(T[i].flag) T[i].res=T[lson].res|T[rson].res;
  29. else T[i].res=T[lson].res^T[rson].res;
  30. }
  31. void update(int i,int d,ll p)
  32. {
  33. if(T[i].l==d&&T[i].r==d){
  34. T[i].res=p;
  35. return ;
  36. }
  37. int m=(T[i].l+T[i].r)>>;
  38. if(d<=m) update(lson,d,p);
  39. else if(d>m) update(rson,d,p);
  40. if(T[i].flag) T[i].res=T[lson].res|T[rson].res;
  41. else T[i].res=T[lson].res^T[rson].res;
  42. }
  43. int main()
  44. {
  45. int n,m,i,k;
  46. while(scanf("%d%d",&n,&m)!=EOF){
  47. for(i=;i<=(<<n);i++) scanf("%I64d",&a[i]);
  48. built(,,(<<n),n&);
  49. for(i=;i<m;i++){
  50. scanf("%d %I64d",&k,&s);
  51. update(,k,s);
  52. printf("%I64d\n",T[].res);
  53. }
  54. }
  55. return ;
  56. }

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. 嵌入式中的 *(volatile unsigned int *)0x500 解释

    C语言中*(volatile unsigned int *)0x500的解释: 如下: (unsigned int *)0x500:将地址0x500强制转化为int型指针*(unsigned int ...

  2. Linux/Android 系统怎么修改mac地址

    使用 busybox ifconfig eth0 hw ether AA:BB:CC:DD:EE 可以修改, 但是每次重启都会改回原来的. 所以要修改 /etc/init.mini210.sh (可能 ...

  3. Java使用FileLock实现Java进程互斥锁

    原理:JDK的nio包中FileLock实现类似Linux fcntl的文件锁, 可使文件被进程互斥访问.  借助此功能, 可以实现强大的Java进程互斥锁, 从而在应用层面保证同一时间只有惟一的Ja ...

  4. NPOI导出word,以及对table的一些设置

    参考网址:http://www.aiuxian.com/article/p-1970779.html NPOI版本:2.1.3.1 最终效果图: 代码: /// <summary> /// ...

  5. 用时间复杂度为n的方法找出水王

    一.题目       三人行设计了一个灌水论坛.信息学院的学生都喜欢在上面交流灌水,传说在论坛上有一个“水王”,他不但喜欢发帖,还会回复其他ID发的每个帖子.坊间风闻该“水王”发帖 数目超过了帖子数目 ...

  6. JS 面向对象之继承 -- 原型链

    ECMAScript只支持实现继承,其实现继承主要是靠原型链来实现. 原型链的基本思想是利用原型让一个引用类型继承另一个引用类型的属性和方法. 简单回顾下构造函数.原型和实例的关系: 每个构造函数都有 ...

  7. Java下Web MVC的领跑者:SpringMVC

    比较常用的MVC框架有Struts 和 SpringMVC. Struts 是Java Web MVC框架中曾经不争的王者.经过长达九年的发展,Struts占有了MVC框架中最大的市场份额.但是Str ...

  8. IT服务系统组成

    软件+硬件+数据 + 运维人员 = IT服务系统 车 司机 乘客 修车 = 车模式 效率 系统 用户 业务 运维 = 信息化 效率 如果司机不会开车,没有人会修车就不会有车轮上的世界 同样没有人会运维 ...

  9. Careercup - Google面试题 - 6283958983589888

    2014-05-06 11:31 题目链接 原题: Find the k-th Smallest Element in Two Sorted Arrays. I followed the algori ...

  10. android sdk manager无法更新(2014-11-6测试OK)--自己收藏用

    问题描述: Android SDK Manager 无法下载更新,或者更新速度超慢,或者待安装包列表不显示. 解决方法:     第一,我们先修改下hosts文件.该文件的位置在系统盘(一般为C盘), ...