Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

真气人 a可以大于b

Posted by liyuweihuo at 2015-08-12 18:16:24 on Problem 2777
#include<stdio.h>
typedef struct 
{
	__int64 flash,m;
}node;
node tree[10*100000];
__int64 cnt;
void ok(__int64 l,__int64 r,__int64 nu)
{
	if(tree[nu].flash)
	{
		tree[nu*2].flash=1;
		tree[nu*2+1].flash=1;
		tree[nu*2].m=tree[nu].m;
		tree[nu*2+1].m=tree[nu].m;
		tree[nu].flash=0;
	}
}
void update(__int64 l,__int64 r,__int64 L,__int64 R,__int64 nu,__int64 m)
{
	if(l==L&&r==R)
	{
		tree[nu].flash=1;
		tree[nu].m=1<<(m-1);
		return ;
	}
	ok(l,r,nu);
	__int64 mid=(l+r)/2;
	if(mid>=R)
	update(l,mid,L,R,2*nu,m);
	else if(mid<L)
	update(mid+1,r,L,R,2*nu+1,m);
	else
	update(l,mid,L,mid,2*nu,m),update(mid+1,r,mid+1,R,2*nu+1,m);
    tree[nu].m=tree[nu*2].m|tree[nu*2+1].m;
}
void query(__int64 l,__int64 r,__int64 L,__int64 R,__int64 nu)
{
	if(l==L&&r==R)
	{
		cnt|=tree[nu].m;
		return ;
	}
	ok(l,r,nu);
	__int64 mid=(l+r)/2;
	if(R<=mid)
	query(l,mid,L,R,2*nu);
	else if(mid<L)
	query(mid+1,r,L,R,2*nu+1);
	else
	query(l,mid,L,mid,2*nu),query(mid+1,r,mid+1,R,2*nu+1);
}
int main()
{
	__int64 l,t,o,a,b,c;
	char s;
	while(~scanf("%I64d%I64d%I64d",&l,&t,&o))
	{
		tree[1].flash=1;
		tree[1].m=1;
		while(o--)
		{
			getchar();
			scanf("%c",&s);
			if(s=='C')
			{
				scanf("%I64d%I64d%I64d",&a,&b,&c);
				if(a>b)
				{
					int t=a;
					a=b;
					b=t;
				}
				update(1,l,a,b,1,c);
			}
			else
			{
				scanf("%I64d%I64d",&a,&b);
				cnt=0;
				if(a>b)
				{
					int t=a;
					a=b;
					b=t;
				}
				query(1,l,a,b,1);
				int sum=0;
				for(int i=0;i<t;i++)
				if(cnt&(1<<i))
				sum++;
				printf("%I64d\n",sum);
			}
		}
	}
	return 0;
} 

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator