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 RUNSLOWLY at 2008-11-04 11:25:08 on Problem 3468
Source Code 
#include<stdio.h>

int main()
{
	__int64 i,str,a,b,tests,n,k;
	__int64 add[100001];
	char c[2];
	scanf("%I64d%I64d",&n,&tests);
	add[0]=0;
	for(i=1;i<=n;i++)
	{
		scanf("%I64d",&str);
		add[i]=add[i-1]+str;
	}

	while(tests--)
	{
    	scanf("%s",c);
		if(c[0]=='Q')
		{
			scanf("%I64d%I64d",&a,&b);
			printf("%I64d\n",add[b]-add[a-1]);
		}
		else
		{
			scanf("%I64d%I64d%I64d",&a,&b,&k);
			for(i=a;i<=b;i++)
				add[i]+=k*(i-a+1);
			k=k*(b-a+1);
			for(;i<=n;i++)
				add[i]+=k;
		}
	}
	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