```cpp
// luogu-judger-enable-o2
#include <bits/stdc++.h>
#define maxn 100000
using namespace std;
typedef struct
{
int val;//0 or 1
bool islzy;
}node;
node st[maxn<<2|1];
inline void pushup(int rt)
{
st[rt].val=st[rt<<1].val+st[rt<<1|1].val;
}
void build(int l,int r,int rt)
{
if(l==r)
{
st[rt].val=0;
st[rt].islzy=false;
return;
}
int mid=(l+r)>>1;
build(l,mid,rt<<1);
build(mid+1,r,rt<<1|1);
pushup(rt);
}
inline void pushdown(int rt,int ln,int rn)
{
if(st[rt].islzy)
{
st[rt].islzy=0;
st[rt<<1].val=ln-st[rt<<1].val;
st[rt<<1|1].val=rn-st[rt<<1|1].val;
st[rt<<1].islzy=st[rt<<1|1].islzy=1;
}
}
void update(int L,int R,int l,int r,int rt)
{
if(L<=l && r<=R)
{
st[rt].val=(r-l+1)-st[rt].val;
st[rt].islzy=1;
return;
}
int mid=(l+r)>>1;
pushdown(rt,mid-l+1,r-mid);
if(L<=mid) update(L,R,l,mid,rt<<1);
if(R>mid) update(L,R,mid+1,r,rt<<1|1);
pushup(rt);
}
int query(int L,int R,int l,int r,int rt)
{
if(L<=l && r<=R)
{
return st[rt].val;
}
if(L>r || R<l)
{
return 0;
}
int m=(l+r)>>1;
pushdown(rt,m-l+1,r-m);
return query(L,R,l,m,rt<<1)+query(L,R,m+1,r,rt<<1|1);
}
int main()
{
int n,m,c,a,b;
scanf("%d %d",&n,&m);
while(m--)
{
scanf("%d %d %d",&c,&a,&b);
if(c==0) update(a,b,1,n,1);
else printf("%d\n",query(a,b,1,n,1));
}
}
```
by minstdfx @ 2019-02-17 21:20:04
蒟蒻码风极差见谅....
by minstdfx @ 2019-02-17 21:20:38
@[用户名已丢失](/space/show?uid=100250)
什么情况
~~刚刚AC来看看~~
by Jelly_Goat @ 2019-02-17 21:32:11
@[用户名已丢失](/space/show?uid=100250)
>希望更丰富的展现?使用Markdown
by gravf @ 2019-02-17 21:40:22
@[用户名已丢失](/space/show?uid=100250) 我猜是这个函数:
```cpp
inline void pushdown(int rt,int ln,int rn)
{
if(st[rt].islzy)
{
st[rt].islzy=0;
st[rt<<1].val=ln-st[rt<<1].val;
st[rt<<1|1].val=rn-st[rt<<1|1].val;
st[rt<<1].islzy=st[rt<<1|1].islzy=1;
}
}
```
by 万弘 @ 2019-02-17 21:44:20
我用了啊@[gravf](/space/show?uid=59221)
by minstdfx @ 2019-02-17 21:44:28
函数怎么改...
by minstdfx @ 2019-02-17 21:44:54
还有pushdown后要pushup
by 万弘 @ 2019-02-17 21:44:59
@[万弘](/space/show?uid=73142)
by minstdfx @ 2019-02-17 21:45:16
具体哪里pushup啊
by minstdfx @ 2019-02-17 21:46:42