ZZULIOJ 1724 candy

Description

Kimi has a lot of candies, and divides them into piles, where the ith pile contains Ai candies. Each time Kimi will choose an interval [l,r], and calculate the total amount of Al,Al+1,…,Ar. It's a hard task, and you're required to solve it.

Input

An integer T(T≤10) will exist in the first line of input, indicating the number of test cases. Each test case begins with the number of piles N(1≤N≤105). The second line contains N integers Ai(1≤Ai≤100), where Ai stands for the number of candies in the ith pile. The next line is the number of queries M(1≤M≤105). The next M lines, each with two integers l,r(1≤lrN), describe the queried intervals.

Output

For each test case, output the total amount of candies in the queried interval.

Sample Input

151 2 4 5 931 22 44 5

Sample Output

31114

看懂题,然后注意不超时就好了。

看懂题是关键_(:з」∠)_

#include<stdio.h>
int a[110000];
int b[110000]={0};
int main()
{
	int t,n,m;
	int i,l,r;
	while(~scanf("%d",&t))
	{
		while(t--)
		{

			scanf("%d",&n);
			for(i=1;i<=n;i++)
			{
				scanf("%d",&a[i]);
				b[i]=b[i-1]+a[i];
			}
			scanf("%d",&m);
			while(m--)
			{
				int sum=0;				
				scanf("%d%d",&l,&r);
				sum=b[r]-b[l-1];
				printf("%d\n",sum);
			}
		}
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值