[Codeforces 339D] Xenia and Bit Operations
[题目链接]
https://codeforces.com/problemset/problem/339/D
[算法]
线段树模拟即可
时间复杂度 :O(MN)
[代码]
- #include<bits/stdc++.h>
- using namespace std;
- #define MAXN 18
- const int MAXS = << MAXN;
- int n , m;
- int a[MAXS];
- struct SegmentTree
- {
- struct Node
- {
- int l , r;
- int value , d;
- } Tree[MAXS << ];
- inline void update(int index)
- {
- if (Tree[index].d == ) Tree[index].value = Tree[index << ].value | Tree[index << | ].value;
- else Tree[index].value = Tree[index << ].value ^ Tree[index << | ].value;
- }
- inline void build(int index,int l,int r)
- {
- Tree[index].l = l;
- Tree[index].r = r;
- if (l == r)
- {
- Tree[index].value = a[l];
- Tree[index].d = ;
- return;
- }
- int mid = (l + r) >> ;
- build(index << ,l,mid);
- build(index << | ,mid + ,r);
- Tree[index].d = (Tree[index << ].d + ) % ;
- update(index);
- }
- inline void modify(int index,int pos,int val)
- {
- if (Tree[index].l == Tree[index].r)
- {
- Tree[index].value = val;
- return;
- }
- int mid = (Tree[index].l + Tree[index].r) >> ;
- if (mid >= pos) modify(index << ,pos,val);
- else modify(index << | ,pos,val);
- update(index);
- }
- inline int query()
- {
- return Tree[].value;
- }
- } T;
- template <typename T> inline void read(T &x)
- {
- T f = ; x = ;
- char c = getchar();
- for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
- for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
- x *= f;
- }
- int main()
- {
- read(n); read(m);
- for (int i = ; i <= ( << n); i++) read(a[i]);
- T.build(,,( << n));
- while (m--)
- {
- int x , y;
- read(x); read(y);
- T.modify(,x,y);
- printf("%d\n",T.query());
- }
- return ;
- }
[Codeforces 339D] Xenia and Bit Operations的更多相关文章
- [线段树]Codeforces 339D Xenia and Bit Operations
Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- CodeForces 339D Xenia and Bit Operations (线段树)
题意:给定 2的 n 次方个数,对这些数两个两个的进行或运算,然后会减少一半的数,然后再进行异或运算,又少了一半,然后再进行或运算,再进行异或,不断重复,到最后只剩下一个数,要输出这个数,然后有 m ...
- codeforces 339C Xenia and Bit Operations(线段树水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Xenia and Bit Operations Xenia the beginn ...
- Xenia and Bit Operations CodeForces - 339D
Xenia and Bit Operations CodeForces - 339D Xenia the beginner programmer has a sequence a, consistin ...
- [codeforces 339]D. Xenia and Bit Operations
[codeforces 339]D. Xenia and Bit Operations 试题描述 Xenia the beginner programmer has a sequence a, con ...
- 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...
- 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 ...
- cf339d Xenia and Bit Operations
Xenia and Bit Operations Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- Xenia and Bit Operations(线段树单点更新)
Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
随机推荐
- CIFAR100与VGG13实战
目录 CIFAR100 13 Layers cafar100_train CIFAR100 13 Layers cafar100_train import tensorflow as tf from ...
- jquery点击事件
$("#hoetelNameSelect").click( $.post("${ctx}/meeting/restaurant/queryHotelName", ...
- Spring之HelloWorld
[Spring是什么?] 1.Spring是一个开源框架. 2.Spring为简化企业级应用开发而生,使用Spring可以使简单的JavaBean实现以前只有EJB(EJB是sun的JavaEE服务器 ...
- [luoguP1037] 产生数(floyd + 高精度)
传送门 先用 floyd 求出每一个数可以变成那些数. 然后利用乘法原理求解,需要高精度. 代码 #include <cstdio> #include <cstring> #i ...
- Linux下汇编语言学习笔记53 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- Network-POJ3694(最小公共祖先LCA+Tarjin)
http://poj.org/problem?id=3694 这一题 为什么要找最小祖先呢 当两个节点连到一块的时候 找最小公共节点就相当于找强连通分支 再找最小公共节点的过程中直到找到 这个过 ...
- HDU——2063 过山车
过山车 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- Canon iP2780/iP2788 清零软件
http://www.drvsky.com/driver/iP2780_Tools.htm http://www.dyjqd.com/soft/6085.html#download http://v. ...
- C#代码读写XML
<1> 创建XML文档 using System; using System.Collections.Generic; using System.Linq; using System.Te ...
- GNS3配置SecureCRT
C:\SecureCRT\SecureCRT.exe /script D:\GNS3\DyRouter.vbs /T /telnet 127.0.0.1 %p "D:\Program Fil ...