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

Here is my code , who can tell me WHY wa, thx!!!

Posted by pozen at 2008-06-27 23:37:08 on Problem 1195
#include <stdio.h>

#define MAX    1025
#define QURRY  2
#define ADD    1
#define INIT   0
#define END    3
#define RET    return
#define INT32  int
#define INT64  long long

INT64 sum_t[MAX][MAX];

INT32 s, ins;

INT32 lowbit(INT32 t)
{
	RET t & (t ^ (t - 1));
}

INT32 plus(INT32 i,INT32 j,INT32 c)
{
	while(i <= s)
	{
		INT32 tempj = j;
		while(tempj <=s)
		{
			sum_t[i][tempj] += c;
            tempj += lowbit(tempj);
		}
		i += lowbit(i);
	}
	RET 0;
}

INT64 get_sum(INT32 i,INT32 j)
{
	INT64 temp = 0;
	while(i > 0)
	{
		INT32 tempj = j;
		while(tempj >0)
		{
			temp += sum_t[i][tempj];
			tempj -= lowbit(tempj);
		}
		i -= lowbit(i);
	}
	RET temp;
}

INT32 main()
{
	//freopen("in.txt","r",stdin);
	while(scanf("%d",&ins) == 1)
	{
		if(ins == INIT)
		{
			scanf("%d",&s);
			for(INT32 i = 1; i <= s; i++)
				for(INT32 j = 1; j <= s; j++)
					sum_t[i][j] = 0;
		}
		else if(ins == ADD)
		{
			INT32 x, y, c;
			scanf("%d%d%d",&x,&y,&c);
			x++,y++;
			plus(x,y,c);
		}
		else if(ins == QURRY)
		{
			INT32 l, b, r, t;
			INT64 sum = 0;
			scanf("%d%d%d%d",&l,&b,&r,&t);
			l++,b++,r++,t++;
			sum += get_sum(t,r);
			if(b-1 > 0) sum -= get_sum(b-1,r);
			if(l-1 > 0) sum -= get_sum(t,l-1);
			if(b-1 > 0 && l-1 > 0) sum += get_sum(b-1,l-1);
			printf("%lld\n",sum);
		}
		else if(ins == END) break;
	}
	RET 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