线段树+状态压缩
#include <stdio.h>

const int LEN = 100005;

struct NODE
  {
int b, e;
int ls, rs;
int color;
int fugai;
}tree[LEN*2];
int nt;

void creat ( int b, int e )
  {

tree[nt].b = b;
tree[nt].e = e;
tree[nt].ls = tree[nt].rs = -1;
tree[nt].color = 0;
tree[nt].fugai = 0;
int p = nt++;

if ( b!=e )
 {
tree[p].ls = nt;
creat ( b, (b+e)/2 );
tree[p].rs = nt;
creat ( (b+e)/2+1, e );
}
}

void chang ( int b, int e, int c, int p )
  {

if ( b==tree[p].b&&e==tree[p].e )
 {
tree[p].fugai = c;
tree[p].color = 1<<c;
return;
}

int ls = tree[p].ls;
int rs = tree[p].rs;
if ( tree[p].fugai!=-1 )
 {
tree[ls].fugai = tree[p].fugai;
tree[ls].color = 1<<tree[p].fugai;
tree[rs].fugai = tree[p].fugai;
tree[rs].color = 1<<tree[p].fugai;
tree[p].fugai = -1;
}

int mid = (tree[p].b+tree[p].e)/2;
if ( e<=mid )
chang ( b, e, c, ls );
else if ( b>mid )
chang ( b, e, c, rs );
else
 {
chang ( b, mid, c, ls );
chang ( mid+1, e, c, rs );
}
tree[p].color = tree[ls].color|tree[rs].color;
}

int ser ( int b, int e, int p )
  {

if ( b==tree[p].b&&e==tree[p].e )
 {
return tree[p].color;
}

int color = 0;
int ls = tree[p].ls;
int rs = tree[p].rs;
if ( tree[p].fugai!=-1 )
 {
tree[ls].fugai = tree[p].fugai;
tree[ls].color = 1<<tree[p].fugai;
tree[rs].fugai = tree[p].fugai;
tree[rs].color = 1<<tree[p].fugai;
tree[p].fugai = -1;
}

int mid = (tree[p].b+tree[p].e)/2;
if ( e<=mid )
color |= ser ( b, e, ls );
else if ( b>mid )
color |= ser ( b, e, rs );
else
 {
color |= ser ( b, mid, ls );
color |= ser ( mid+1, e, rs );
}
return color;
}

int main ()
  {

int l, t, o;
scanf ( "%d%d%d", &l, &t, &o );
nt = 0;
creat ( 0, l-1 );
for ( int i=0; i<o; i++ )
 {
char str[5];
int b, e, c;
scanf ( "%s", str );
if ( str[0]=='C' )
 {
scanf ( "%d%d%d", &b, &e, &c );
if ( b>e )
 {
int tmp = b;
b = e;
e = tmp;
}
if ( e<=0||b>l )
continue;
if ( b<=0 )
b = 1;
if ( e>l )
e = l;
chang ( b-1, e-1, c-1, 0 );
}
else if ( str[0]=='P' )
 {
scanf ( "%d%d", &b, &e );
if ( b>e )
 {
int tmp = b;
b = e;
e = tmp;
}
if ( e<=0||b>l )
 {
printf ( "0\n" );
continue;
}
if ( b<=0 )
b = 1;
if ( e>l )
e = l;
int color = ser ( b-1, e-1, 0 );
int ans = 0;
while ( color )
 {
if ( color&1 )
ans ++;
color >>= 1;
}
printf ( "%d\n", ans );
}
}
return 0;
}

|
|
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
25 | 26 | 27 | 28 | 29 | 30 | 31 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 1 | 2 | 3 | 4 | 5 |
|
公告
决定从线程开始!!
常用链接
留言簿(6)
随笔档案
搜索
最新评论

阅读排行榜
评论排行榜
|
|