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

Re:大牛们,都说牛吃的是草,挤出来的是奶,跪求就挤些出来吧,赐教一下初学者^_^

Posted by ZYWei at 2008-05-07 08:29:56 on Problem 3468
In Reply To:Re:谁能帮我看看这个代码,线段树处理的这道题,怎么就超时呢?跪求大牛给个解释吧 Posted by:ZYWei at 2008-05-07 08:26:41
#include<stdio.h>
int main()
{
	int N,Q;
	scanf("%d%d",&N,&Q);
	__int64* num=new __int64[N];
	int i;
	for(i=0;i<N;i++)
		scanf("%I64d",&num[i]);
	while(Q!=0)
	{
		getchar();
		char letter;
		int a,b,c;
		scanf("%c%d%d",&letter,&a,&b);
		if(letter=='C')
		{
			scanf("%d",&c);
			for(i=a-1;i<b;i++)
				num[i]=num[i]+c;
		}
		else
		{
			__int64 sum=0;
			for(i=a-1;i<b;i++)
				sum=sum+num[i];
			printf("%I64d\n",sum);
		}
		Q--;
	}
	return 0;
}
这种算法时间复杂度才 O(Q*N)明显比上面的那种线段树的解法还要快的多的呀,怎么这种还是要超时呢?好心的大牛,给个解释吧

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