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

求救,错哪了?

Posted by seriousError at 2011-04-09 23:11:13 on Problem 2777
#include<iostream>
#define N 500000
using namespace std;
struct node
{
	int l,r,col;
	bool si;
}nd[N];
int ans;
void build(int a,int b,int v)
{
	nd[v].l =a;
	nd[v].r=b;
	nd[v].col=1;
	nd[v].si=1;
	if(nd[v].l<nd[v].r)
	{
		int mid=(nd[v].l+nd[v].r)>>1;
		build(a,mid,2*v);
		build(mid+1,b,2*v+1);
	}
}
void insert(int a,int b,int v,int q)
{
	if(nd[v].l==nd[v].r)
	{
		nd[v].col=(1<<(q-1));
		return;
	}
	int mid=(nd[v].l+nd[v].r)>>1;
	if(a<=mid)insert(a,b,2*v,q);
	if(b>mid)insert(a,b,2*v+1,q);
	nd[v].col =nd[2*v].col | nd[2*v+1].col;
	if(nd[2*v].col==nd[2*v+1].col)nd[v].si=1;
	else nd[v].si=0;
}
void search(int a,int b,int v)
{
	if(nd[v].si)
	{
		ans |= nd[v].col;
		return;
	}
	if(nd[v].l>=a&&nd[v].r<=b)
	{
		ans |=nd[v].col;
		return;
	}
	int mid=(nd[v].l+nd[v].r)>>1;
	if(a<=mid)
		search(a,b,2*v);
	if(b>mid)
		search(a,b,2*v+1);
}
int main()
{
	int L,T ,O;
	int m,n,c;
	char ch;
	scanf_s("%d %d %d",&L,&T ,&O);
	build(1,L,1);
	while(O--)
	{
		cin>>ch;
		if(ch=='C')
		{
			scanf_s("%d %d %d",&m,&n,&c);
			if(m<n)insert(m,n,1,c);
			else insert(n,m,1,c);
		}
		else
		{
			ans=0;
			int an=0;
			int bit=1;
			scanf_s("%d %d",&m,&n);
			if(m<n)search(m,n,1);
			else search(n,m,1);
			while(bit<=ans)
			{
				if(ans&bit)an++;
				bit<<=1;
			}
			printf_s("%d\n",an);
		}
	}
}

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