Xenia and Bit Operations 【CodeForces - 339D】【线段树+位运算】

题目链接


  这道题难理解也就在于题意了,题目要求的是对于原来的这个数(一共(1<

  每个查询会改变某一点的值,然后输出整个的答案。


#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define lowbit(x) ( x&(-x) )
#define pi 3.141592653589793
#define e 2.718281828459045
#define INF 0x3f3f3f3f
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int maxN = 3e5 + 7;
int N, tot, M, tree[maxN<<2];
void buildTree(int rt, int l, int r, int div)
{
    if(l == r)
    {
        scanf("%d", &tree[rt]);
        return;
    }
    int mid = HalF;
    buildTree(Lson, div - 1);
    buildTree(Rson, div - 1);
    if(div & 1) tree[rt] = tree[lsn] ^ tree[rsn];
    else tree[rt] = tree[lsn] | tree[rsn];
}
void update(int rt, int l, int r, int qx, int val, int div)
{
    if(l == r) { tree[rt] = val;    return; }
    int mid = HalF;
    if(qx <= mid) update(Lson, qx, val, div - 1);
    else update(Rson, qx, val, div - 1);
    if(div & 1) tree[rt] = tree[lsn] ^ tree[rsn];
    else tree[rt] = tree[lsn] | tree[rsn];
}
int main()
{
    scanf("%d%d", &N, &M);
    tot = 1<

 

你可能感兴趣的:(线段树,数据结构)