Topic Portal
1 /*2 single point update for segment tree: There is a cross-update, if Rank=1,or;rank=0,xor3 Detailed Explanation:http://www.xuebuyuan.com/1154895.html4 */5#include <cstdio>6#include <iostream>7#include <algorithm>8#include <cstring>9#include <string>Ten#include <cmath> One#include <Set> A#include <map> - using namespacestd; - #defineLson L, Mid, RT << 1 the #defineRson mid+1, R, RT << 1 | 1 - - Const intMAXN =1<< -|1; - Const intINF =0x3f3f3f3f; + structNODE - { + intV, MX, MN, sum; A intrank; at}NODE[MAXN <<2]; - - voidPUSH_UP (intRT) - { - if(node[rt<<1].rank = =1) - { inNode[rt].rank =0; -NODE[RT].V = node[rt<<1].V | node[rt<<1|1].v; to } + Else - { theNode[rt].rank =1; *NODE[RT].V = node[rt<<1].v ^ node[rt<<1|1].v; $ }Panax Notoginseng } - the + voidBuildintLintRintRT) A { the if(L = =R) + { -scanf ("%d", &node[rt].v); $Node[rt].rank =1; $ return ; - } - intMid = (L + r) >>1; the build (Lson); - build (Rson);Wuyi the push_up (RT); - } Wu - voidUpdata (intPintBintLintRintRT) About { $ if(L = =R) - { -NODE[RT].V =b; - return ; A } + intMid = (L + r) >>1; the if(P <=mid) Updata (p, B, Lson); - ElseUpdata (p, B, Rson); $ the push_up (RT); the } the the - intMainvoid)//codeforces Round #197 (Div. 2) D. Xenia and Bit Operations in { the //freopen ("h.in", "R", stdin); the About intN, M; thescanf ("%d%d", &n, &m); theBuild (1,1<<n,1); the + intp, b; - for(intI=1; i<=m; ++i) the {Bayiscanf ("%d%d", &p, &b); theUpdata (p, B,1,1<<n,1); theprintf ("%d\n", node[1].v); - } - the return 0; the}
Segment Tree Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations