| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
输入T并没有什么卵子用上代码:(用bitset即可)
#include<cstdio>
#include<bitset>
#include<cstring>
#include<algorithm>
using namespace std;
/*
好容器bitset
bool any( )
是否存在值为1的二进制位?
bool none( )
是否全部为0?
flip()
把所有二进制位逐位取反
set()
把所有二进制位都赋值为1
set(pos)
把在pos处的二进制位赋值为1
reset()
把所有二进制位都赋值为0
count()
获得有多少个1
*/
struct trnode
{
int l,r,lc,rc,lazy;
bitset<51> c;
}tr[2110000];int len;
void bt(int l,int r)
{
int now=++len;
tr[now].l=l;tr[now].r=r;tr[now].lazy=0;
tr[now].c.reset();tr[now].c[1]=1;
if(l==r) tr[now].lc=tr[now].rc=-1;
else
{
int mid=(l+r)>>1;
tr[now].lc=len+1;bt(l,mid);
tr[now].rc=len+1;bt(mid+1,r);
}
}
void update(int now,int lc,int rc)
{
int lazy=tr[now].lazy;
tr[lc].lazy=lazy;
tr[lc].c.reset();tr[lc].c[lazy]=1;
tr[rc].lazy=lazy;
tr[rc].c.reset();tr[rc].c[lazy]=1;
tr[now].lazy=0;
}
void change(int now,int l,int r,int k)
{
if(tr[now].l==l && tr[now].r==r)
{
tr[now].c.reset();
tr[now].c[k]=1;
tr[now].lazy=k;
return ;
}
int mid=(tr[now].l+tr[now].r)>>1;
int lc=tr[now].lc,rc=tr[now].rc;
if(tr[now].lazy!=0) update(now,lc,rc);
if(r<=mid) change(lc,l,r,k);
else if(l>mid) change(rc,l,r,k);
else
{
change(lc,l,mid,k);
change(rc,mid+1,r,k);
}
tr[now].c=(tr[lc].c|tr[rc].c);
}
bitset<51> ans;
void solve(int now,int l,int r)
{
if(tr[now].l==l && tr[now].r==r)
{
ans=(ans|tr[now].c);
return ;
}
int mid=(tr[now].l+tr[now].r)>>1;
int lc=tr[now].lc,rc=tr[now].rc;
if(tr[now].lazy!=0) update(now,lc,rc);
if(r<=mid) solve(lc,l,r);
else if(l>mid) solve(rc,l,r);
else
{
solve(lc,l,mid);
solve(rc,mid+1,r);
}
}
char s[10];
int x,y,z,n,m,T;
int main()
{
// freopen("1100.in","r",stdin);
// freopen("1100.out","w",stdout);
scanf("%d%d%d",&n,&T,&m);
bt(1,n);
for(int i=1;i<=m;i++)
{
scanf("%s%d%d",s,&x,&y);
if(x>y) x^=y^=x^=y;
if(s[0]=='C')
{
scanf("%d",&z);
change(1,x,y,z);
}
else
{
ans.reset();
solve(1,x,y);
printf("%d\n",ans.count());
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator