这是之前比赛的一道题目,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 &&