Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:大牛们,都说牛吃的是草,挤出来的是奶,跪求就挤些出来吧,赐教一下初学者^_^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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator