【Codeforces 339 D - Xenia and Bit Operations 】线段树 底层或上层异或

博客详细讲解了Codeforces 339D问题,涉及线段树的底层与上层异或和或操作。在构建线段树时,底层保持原样,上一层使用按位或(|)合并,再上一层使用按位异或(^)合并,依此类推。文章提到了在更新线段树时根据层数判断使用|还是^的关键技巧。
摘要由CSDN通过智能技术生成

CF339D
底层 或 上层 异或
题意 这题其实很有意思的 首先给你 n 和 Q
然后给你 2^n个数字 也就是一颗满的线段树
然后对底层 他是不处理 底层的上一层 用 | 去合并
然后再上一层 用 ^ 去合并
再上一层 用 | 去合并
以此类推
这样的话其实这题很骚
也就是教会了我们在up函数魔改
首先build 到底层的时候那么就是 col[rt] = -1 然后 上一层就是col[rt<<1] + 1 = 0
再上一层 就是 0 + 1 = 1
那么我们只要在up的时候判断奇偶来决定是 | 还是 ^ 就行了

/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define lc (rt<<1)
#define rc (rt<<11)
#define mid ((l+r)>>1)

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值