[题目链接]

https://codeforces.com/problemset/problem/339/D

[算法]

线段树模拟即可

时间复杂度 :O(MN)

[代码]

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define MAXN 18
  4. const int MAXS = << MAXN;
  5.  
  6. int n , m;
  7. int a[MAXS];
  8.  
  9. struct SegmentTree
  10. {
  11. struct Node
  12. {
  13. int l , r;
  14. int value , d;
  15. } Tree[MAXS << ];
  16. inline void update(int index)
  17. {
  18. if (Tree[index].d == ) Tree[index].value = Tree[index << ].value | Tree[index << | ].value;
  19. else Tree[index].value = Tree[index << ].value ^ Tree[index << | ].value;
  20. }
  21. inline void build(int index,int l,int r)
  22. {
  23. Tree[index].l = l;
  24. Tree[index].r = r;
  25. if (l == r)
  26. {
  27. Tree[index].value = a[l];
  28. Tree[index].d = ;
  29. return;
  30. }
  31. int mid = (l + r) >> ;
  32. build(index << ,l,mid);
  33. build(index << | ,mid + ,r);
  34. Tree[index].d = (Tree[index << ].d + ) % ;
  35. update(index);
  36. }
  37. inline void modify(int index,int pos,int val)
  38. {
  39. if (Tree[index].l == Tree[index].r)
  40. {
  41. Tree[index].value = val;
  42. return;
  43. }
  44. int mid = (Tree[index].l + Tree[index].r) >> ;
  45. if (mid >= pos) modify(index << ,pos,val);
  46. else modify(index << | ,pos,val);
  47. update(index);
  48. }
  49. inline int query()
  50. {
  51. return Tree[].value;
  52. }
  53. } T;
  54.  
  55. template <typename T> inline void read(T &x)
  56. {
  57. T f = ; x = ;
  58. char c = getchar();
  59. for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
  60. for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
  61. x *= f;
  62. }
  63.  
  64. int main()
  65. {
  66.  
  67. read(n); read(m);
  68. for (int i = ; i <= ( << n); i++) read(a[i]);
  69. T.build(,,( << n));
  70. while (m--)
  71. {
  72. int x , y;
  73. read(x); read(y);
  74. T.modify(,x,y);
  75. printf("%d\n",T.query());
  76. }
  77.  
  78. return ;
  79.  
  80. }

[Codeforces 339D] Xenia and Bit Operations的更多相关文章

  1. [线段树]Codeforces 339D Xenia and Bit Operations

    Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

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

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

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

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

  4. Xenia and Bit Operations CodeForces - 339D

    Xenia and Bit Operations CodeForces - 339D Xenia the beginner programmer has a sequence a, consistin ...

  5. [codeforces 339]D. Xenia and Bit Operations

    [codeforces 339]D. Xenia and Bit Operations 试题描述 Xenia the beginner programmer has a sequence a, con ...

  6. 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

    题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...

  7. Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

    D. Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input ...

  8. cf339d Xenia and Bit Operations

    Xenia and Bit Operations Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  9. Xenia and Bit Operations(线段树单点更新)

    Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

随机推荐

  1. CIFAR100与VGG13实战

    目录 CIFAR100 13 Layers cafar100_train CIFAR100 13 Layers cafar100_train import tensorflow as tf from ...

  2. jquery点击事件

    $("#hoetelNameSelect").click( $.post("${ctx}/meeting/restaurant/queryHotelName", ...

  3. Spring之HelloWorld

    [Spring是什么?] 1.Spring是一个开源框架. 2.Spring为简化企业级应用开发而生,使用Spring可以使简单的JavaBean实现以前只有EJB(EJB是sun的JavaEE服务器 ...

  4. [luoguP1037] 产生数(floyd + 高精度)

    传送门 先用 floyd 求出每一个数可以变成那些数. 然后利用乘法原理求解,需要高精度. 代码 #include <cstdio> #include <cstring> #i ...

  5. Linux下汇编语言学习笔记53 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  6. Network-POJ3694(最小公共祖先LCA+Tarjin)

    http://poj.org/problem?id=3694 这一题  为什么要找最小祖先呢 当两个节点连到一块的时候  找最小公共节点就相当于找强连通分支 再找最小公共节点的过程中直到找到  这个过 ...

  7. HDU——2063 过山车

    过山车 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  8. Canon iP2780/iP2788 清零软件

    http://www.drvsky.com/driver/iP2780_Tools.htm http://www.dyjqd.com/soft/6085.html#download http://v. ...

  9. C#代码读写XML

    <1> 创建XML文档 using System; using System.Collections.Generic; using System.Linq; using System.Te ...

  10. GNS3配置SecureCRT

    C:\SecureCRT\SecureCRT.exe /script D:\GNS3\DyRouter.vbs /T /telnet 127.0.0.1 %p "D:\Program Fil ...