Count Color(线段树+位运算)

这是之前比赛的一道题目,HD训练题上又遇到了,直接A了,其实就是将求和操作变成|=运算符,用位运算压缩T种颜色,这样每个结点上维护的就是其所覆盖的颜色种类数。

细节参见代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
using namespace std;
const int maxn = 100000 + 5;
int T,n,q,y11,y22,v,kase=0,_sum,sumv[3*maxn],setv[maxn*3];
void pushdown(int o) {
    int lc = o*2, rc = o*2+1;
    if(setv[o] >= 0) {
        setv[lc] = setv[rc] = setv[o];
        setv[o] = -1;
    }
}
void maintain(int o, int L, int R) {
    int lc = o*2, rc = o*2+1;
    sumv[o] = 0;
    if(R > L) {
        sumv[o] |= sumv[lc];
        sumv[o] |= sumv[rc];
    }
    if(setv[o]>=0) sumv[o] = setv[o];
}
void update(int o, int L, int R) {
    int lc = o*2, rc = o*2+1;
    if(y11 <= L &&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值