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

大家帮忙看一下吧tle的不行了。。实在不知道那里错了。

Posted by star6 at 2007-04-18 23:05:33 on Problem 1195
#include<cstdio>
#include<algorithm>

const	int		maxn=1024;

int		a[maxn][maxn];
int		s;

int		lowbit(int	a)
{
	return(a&(-a));
}

void	update(int	x,int	y,int	t)
{
	int		i,j;
	
	for (i=x;i<=s;i+=lowbit(i))
		for (j=y;j<=s;j+=lowbit(j))
			a[i][j]+=t;
}

int		sum(int	x1,int	y1,int	x2,int	y2)
{
	int		i,j,ti,tj,count;
	
	count=0;
	
	for (i=x2;(i>x1)&&(i);i-=lowbit(i))
	{
		for (j=y2;(j>y1)&&(j);j-=lowbit(j))
			count+=a[i][j];
		tj=j;
		for (j=y1-1;j>tj;j-=lowbit(j))
			count-=a[i][j];
	}
	
	ti=i;	
	for (i=x1-1;i>ti;i-=lowbit(i))
	{
		for (j=y2;j>tj;j-=lowbit(j))
			count-=a[i][j];
		for (j=y1-1;j>tj;j-=lowbit(j))
			count+=a[i][j];
	}
		
	return(count);			
}

int		main()
{	
	int		key;
	int		x,y,t;
	int		x1,y1,x2,y2;
	
//	freopen("c:\\in.txt","r",stdin);
	
		
	do
	{
		scanf("%d",&key);
		switch(key)
		{
			case 0:
				scanf("%d\n",&s);
				memset(a,0,sizeof(a));
				break;
			case 1:
				scanf("%d %d %d\n",&x,&y,&t);
				update(x,y,t);
				break;
			case 2:
				scanf("%d %d %d %d\n",&x1,&y1,&x2,&y2);
				printf("%d\n",sum(x1,y1,x2,y2));
				break;			
		}
	}while (key!=3);
	
	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