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

帮帮忙~搞了好几天~~搞的晕头转向还是不懂自己哪里写错了...我怎么觉的自己米错...希望大家指点一下,提供一些数据也可以~thx....

Posted by majia5 at 2009-02-07 12:00:15 on Problem 2777
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<string>
using namespace std;
struct Node
{
	int l,r,data;
}s[262145];
bool flag[262145];
bool cnt[31];
int L,T;
void mkseg(int l,int r,int x)
{
	s[x].l=l;
	s[x].r=r;
	s[x].data=-1;
	flag[x]=true;
	if(l+1==r)return;
	int mid=(l+r)/2;
	mkseg(l,mid,2*x);
	mkseg(mid,r,2*x+1);
}
void clc(int x)//这里应该没写错吧?
{
	if(s[x].l+1!=s[x].r)
	{
		if(s[x].data!=-1)
			s[2*x].data=s[2*x+1].data=s[x].data,s[x].data=-1;
	}
}
void ins(int l,int r,int c,int x)
{
	if(!flag[x])return;
	if(l<=s[x].l&&s[x].r<=r&&c==s[x].data)return;//如果完全覆盖并且要插入的颜色和待插入的区间颜色本来就一样
	clc(x);//清处节点
	if(l<=s[x].l&&s[x].r<=r)
	{
		s[x].data=c;
		return;
	}
	if(s[x].l+1==s[x].r)return;
	int mid=(s[x].l+s[x].r)/2;
	if(r<=mid)ins(l,r,c,2*x);else if(l>=mid)ins(l,r,c,2*x+1);else ins(l,mid,c,2*x),ins(mid,r,c,2*x+1);
}
void q(int l,int r,int x)//查询
{
	if(!flag[x])return;
	if(l<=s[x].l&&s[x].r<=r)
	{
		if(s[x].data!=-1)
		{
			cnt[s[x].data]=true;
			return;
		}
	}
	if(s[x].l+1==s[x].r)return;
	int mid=(s[x].l+s[x].r)/2;
	if(r<=mid)q(l,r,2*x);else if(l>=mid)q(l,r,2*x+1);else q(l,mid,2*x),q(mid,r,2*x+1);
}
void query(int l,int r)
{
	int i,ret=0;
	memset(cnt,false,sizeof(cnt));
	q(l,r,1);
	for(i=1;i<=T;i++)if(cnt[i])ret++;
	printf("%d\n",ret);
}
int main()
{
	int Q;
	char op;
	int l,r,c;
	scanf("%d%d%d%*c",&L,&T,&Q);
	mkseg(1,L+1,1);
	ins(1,L+1,1,1);
	while(Q--)
	{
		scanf("%c",&op);
		if(op=='C')
		{
			scanf("%d%d%d%*c",&l,&r,&c);
			if(l>r)swap(l,r);
			r++;
			ins(l,r,c,1);
		}
		else
		{
			scanf("%d%d%*c",&l,&r);
			if(l>r)swap(l,r);
			r++;
			query(l,r);
		}
	}
	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