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 heidaizx at 2008-08-10 18:05:46 on Problem 2155
//用树状数组做的,不知道为什么会超时
#include<iostream>
#include<cstring>
using namespace std;

char c;
int lowbit(int n)
{
	return n&(-n);
}
void modify(int begina,int beginb,int enda,int endb,int **a)
{
	int i,j;
	for(i=begina;i<=enda;i+=lowbit(i))
	{
		for(j=beginb;j<=endb;j+=lowbit(j))
		{
			if(a[i][j]==0)
				a[i][j]+=1;
			else
				a[i][j]-=1;
		}
	}
}
int sum(int i,int j,int **a)
{
	int x,y;
	int result=0;
	for(x=i;x>=1;x-=lowbit(x))
	{
		for(y=j;y>=1;y-=lowbit(y))
		{
			result+=a[x][y];
		}
	}
//	cout<<result;
	return result;
}

int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		
		int N,T,i,j;
		cin>>N>>T;
		int **p=new int *[N];
		for(i=1;i<=N;i++)
		{
			p[i]=new int[T];
			
		}
		for(i=1;i<=N;i++)
		{
			for(j=1;j<=N;j++)
			{
				p[i][j]=0;
			}
		}
		for(i=1;i<=N;i++)
		
		while(true)
		{
			cin>>c;
			if(c=='C')
			{
				int begina,beginb,enda,endb;
				cin>>begina>>beginb>>enda>>endb;
				modify(begina,beginb,enda,endb,p);
				T--;
			}
			else
			{
				cin>>i>>j;
				cout<<sum(i,j,p)<<endl;
				T--;
			}
			if(T==0)break;
			
		}
		delete[]p;
		if(n)cout<<endl;
	}

	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