ZZULIOJ 1724 candy
2015-12-02 13:26
381 查看
Description
Kimi has a lot of candies, and divides them into piles, where theith 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 pilesN(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≤l≤r≤N), 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; }
相关文章推荐
- 51nod 1394:差和问题
- The archive :xxx.jar which is referenced by the classpath, does not exist
- Android开发随手记
- 关于文件系统
- 分布式设计与开发
- es6
- 关于Android中传递数据的一些讨论--备用
- Backbone框架+流程图
- UICollectionView实现Beginupdates
- solr环境搭建(三)
- 【LEETCODE】310-Minimum Height Trees
- linux中ip和防火墙
- 打电话、发短信
- [ 学习路线 ] 2015 前端(JS)工程师必知必会 (2)
- ZZULIOJ 1302 海军节上的鸣炮声计算
- 腾讯开发平台 手机QQ登录 错误码:110406 解决办法;新浪微博sso错误
- 使用IPTABLES实现对特定IP, 3ff8 端口流量的精确统计
- 利用findBugs插件来扫描代码,并用ant生成报告
- Skyline中目录树的遍历
- Flume-NG 的原理和使用