您的位置:首页 > 运维架构

线段树 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: