码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-04-08 14:44:04      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

 

题目传送门

 1 /*
 2     线段树的单点更新:有一个交叉更新,若rank=1,or;rank=0,xor
 3     详细解释:http://www.xuebuyuan.com/1154895.html
 4 */
 5 #include <cstdio>
 6 #include <iostream>
 7 #include <algorithm>
 8 #include <cstring>
 9 #include <string>
10 #include <cmath>
11 #include <set>
12 #include <map>
13 using namespace std;
14 #define lson l, mid, rt << 1
15 #define rson mid+1, r, rt << 1 | 1
16 
17 const int MAXN = 1 << 17 | 1;
18 const int INF = 0x3f3f3f3f;
19 struct NODE
20 {
21     int v, mx, mn, sum;
22     int rank;
23 }node[MAXN << 2];
24 
25 void push_up(int rt)
26 {
27     if (node[rt<<1].rank == 1)
28     {
29         node[rt].rank = 0;
30         node[rt].v = node[rt<<1].v | node[rt<<1|1].v;
31     }
32     else
33     {
34         node[rt].rank = 1;
35         node[rt].v = node[rt<<1].v ^ node[rt<<1|1].v;
36     }
37 }
38 
39 
40 void build(int l, int r, int rt)
41 {
42     if (l == r)
43     {
44         scanf ("%d", &node[rt].v);
45         node[rt].rank = 1;
46         return ;
47     }
48     int mid = (l + r) >> 1;
49     build (lson);
50     build (rson);
51 
52     push_up (rt);
53 }
54 
55 void updata(int p, int b, int l, int r, int rt)
56 {
57     if (l == r)
58     {
59         node[rt].v = b;
60         return ;
61     }
62     int mid = (l + r) >> 1;
63     if (p <= mid)    updata (p, b, lson);
64     else    updata (p, b, rson);
65 
66     push_up (rt);
67 }
68 
69 
70 int main(void)        //Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
71 {
72     //freopen ("H.in", "r", stdin);
73 
74     int n, m;
75     scanf ("%d%d", &n, &m);
76     build (1, 1<<n, 1);
77 
78     int p, b;
79     for (int i=1; i<=m; ++i)
80     {
81         scanf ("%d%d", &p, &b);
82         updata (p, b, 1, 1<<n, 1);
83         printf ("%d\n", node[1].v);
84     }
85 
86     return 0;
87 }

 

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

标签:

原文地址:http://www.cnblogs.com/Running-Time/p/4402189.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!