| ||||||||||
| 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 | |||||||||
不知道哪里错了,哪位大牛给看下啊,改了好久了#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxlen=100010;
struct node
{
int l;
int r;
int sure;
int c;
}a[maxlen*4];
bool vis[40];
void build(int l,int r,int step)
{
a[step].l=l;
a[step].r=r;
a[step].c=0;
a[step].sure=0;
if(l==r)
{
a[step].c=1;
a[step].sure=1;
return;
}
else
{
build(l,(l+r)/2,step*2);
build((l+r)/2+1,r,step*2+1);
}
}
void insert(int l,int r,int c,int step)
{
//cout<<a[step].l<<' '<<a[step].r<<' '<<c<<' '<<step<<endl;
if(a[step].c==c&&a[step].sure)
return ;
if(a[step].l==l&&a[step].r==r)
{
a[step].c=c;
a[step].sure=1;
return ;
}
int mid=(a[step].l+a[step].r)/2;
if(a[step].l==a[step].r)
return ;
if(a[step].sure)
{
a[step].sure=0;
a[step*2].sure=1;
a[step*2].c=a[step].c;
a[step*2+1].sure=1;
a[step*2+1].c=a[step].c;
}
if(mid>=r)
{
insert(l,r,c,step*2);
}
else
{
if(mid<l)
{
insert(l,r,c,step*2+1);
}
else
{
insert(l,mid,c,step*2);
insert(mid+1,r,c,step*2+1);
}
}
}
void query(int l,int r,int step)
{
//cout<<a[step].l<<' '<<l<<' '<<a[step].r<<' '<<r<<' '<<a[step].c<<' '<<a[step].sure <<endl;
if(a[step].l>=l&&a[step].r<=r&&a[step].sure)
{
//cout<<"return "<<endl;
vis[a[step].c]=1;
return ;
}
int mid=(a[step].l+a[step].r)/2;
if(a[step].l==a[step].r)
return ;
if(a[step].sure)
{
a[step*2].sure=1;
a[step*2].c=a[step].c;
a[step*2+1].sure=1;
a[step*2+1].c=a[step].c;
}
if(mid>=r)
{
query(l,r,step*2);
}
else
{
if(mid<l)
{
query(l,r,step*2+1);
}
else
{
//cout<<"mid"<<endl;
query(l,mid,step*2);
query(mid+1,r,step*2+1);
}
}
}
int main()
{
int L,T,O;
char oper;
int i;
int l,r,c;
int temp;
int j;
scanf("%d%d%d",&L,&T,&O);
{
build(1,L,1);
//cout<<"c f"<<endl;
for(i=0;i<O;i++)
{
getchar();
scanf("%c",&oper);
if(oper=='C')
{
scanf("%d%d%d",&l,&r,&c);
if(l>r)
{
temp=l;
l=r;
r=temp;
}
insert(l,r,c,1);
}
else
{
int count=0;
memset(vis,0,sizeof(vis));
scanf("%d%d",&l,&r);
if(l>r)
{
temp=l;
l=r;
r=temp;
}
query(l,r,1);
for(j=0;j<30;j++)
{
if(vis[j])
count++;
}
printf("%d\n",count);
//cout<<count<<endl;
}
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator