线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
2015-04-08 13:37
471 查看
题目传送门
/* 线段树的单点更新:有一个交叉更新,若rank=1,or;rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <string> #include <cmath> #include <set> #include <map> using namespace std; #define lson l, mid, rt << 1 #define rson mid+1, r, rt << 1 | 1 const int MAXN = 1 << 17 | 1; const int INF = 0x3f3f3f3f; struct NODE { int v, mx, mn, sum; int rank; }node[MAXN << 2]; void push_up(int rt) { if (node[rt<<1].rank == 1) { node[rt].rank = 0; node[rt].v = node[rt<<1].v | node[rt<<1|1].v; } else { node[rt].rank = 1; node[rt].v = node[rt<<1].v ^ node[rt<<1|1].v; } } void build(int l, int r, int rt) { if (l == r) { scanf ("%d", &node[rt].v); node[rt].rank = 1; return ; } int mid = (l + r) >> 1; build (lson); build (rson); push_up (rt); } void updata(int p, int b, int l, int r, int rt) { if (l == r) { node[rt].v = b; return ; } int mid = (l + r) >> 1; if (p <= mid) updata (p, b, lson); else updata (p, b, rson); push_up (rt); } int main(void) //Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations { //freopen ("H.in", "r", stdin); int n, m; scanf ("%d%d", &n, &m); build (1, 1<<n, 1); int p, b; for (int i=1; i<=m; ++i) { scanf ("%d%d", &p, &b); updata (p, b, 1, 1<<n, 1); printf ("%d\n", node[1].v); } return 0; }
相关文章推荐
- Codeforces Round #197 (Div. 2) -- D. Xenia and Bit Operations(线段树)
- Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations - 线段树
- Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations(线段树)
- codeforces 339 D.Xenia and Bit Operations(线段树)
- Xenia and Bit Operations 【线段树】
- CodeForces 339D D. Xenia and Bit Operations(线段树的单点更新)
- CF 339D - Xenia and Bit Operations(线段树)
- Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
- Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
- Xenia and Bit Operations(线段树单点更新)
- 文章标题 coderforces 339D : Xenia and Bit Operations (线段树+点修改)
- codeforces 339 D.Xenia and Bit Operations(线段树)
- #Codeforces 343 [div2] D. Babaei and Birthday Cake 【线段树优先队列查询优化】
- Bit shifting and bitwise operations
- Codeforces Round #393 (Div. 2) E题Nikita and stack(线段树)解题报告
- 【TC SRM 596 DIV1】BitwiseAnd
- Codeforces Round #284 (Div. 1) C. Array and Operations 二分图最大匹配
- Codeforces Round #250 (Div. 1) D. The Child and Sequence (线段树)
- BestCoder Round #56 1002 Clarke and problem 1003 Clarke and puzzle (dp,二维bit或线段树)
- 有趣的线段树小集合 Codeforces Round #250 (Div. 1) D. The Child and Sequence