cdoj1259 线段树+bitset

感觉题目简单,就看你的bitset怎么用了。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define maxn 160005
using namespace std;
struct ee
{
    int l,r,lazy;
    bitset<120> s;
}tree[maxn*4];
int n,m;

void build_tree(int root,int l,int r)
{
    tree[root].l=l;
    tree[root].r=r;
    tree[root].lazy=0;
    tree[root].s.reset();
    if(l==r)
        return;
    int mid=(l+r)/2;
    build_tree(2*root,l,mid);
    build_tree(2*root+1,mid+1,r);
}

void pushdown(int a)
{

    tree[a].s.reset();
    tree[a].s|=tree[a*2].s;
    tree[a].s|=tree[a*2+1].s;
}

void pushup(int a,int l)
{
    tree[a*2].lazy=l;
    tree[a*2].s.reset();
    tree[a*2].s[l]=1;
    tree[a*2+1].lazy=l;
    tree[a*2+1].s.reset();
    tree[a*2+1].s[l]=1;
}

bitset<120> query(int root,int l,int r)
{
    if(tree[root].lazy!=0)
    {
        pushup(root,tree[root].lazy);
        tree[root].lazy=0;
    }
    if(l<=tree[root].l&&tree[root].r<=r)
        return tree[root].s;
    bitset<120> bit;
    bit.reset();
    int mid;
    mid=(tree[root].l+tree[root].r)/2;
    if(l<=mid)
    bit|=query(root*2,l,r);
    if(mid

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