题解 | 【模板】静态区间和(前缀和)

【模板】静态区间和(前缀和)

https://www.nowcoder.com/practice/ac79a1a4a66646cc87525d6faa86e021

n, q = map(int,input().split())
a = list(map(int,input().split()))

ans, dp = 0, []
for c in a:#制造前缀和列表
    ans += c
    dp.append(ans)

for _ in range(q):#输出区间前缀和
    l, r = map(int,input().split())
    if l==1:
        print(dp[r-1])
    else:
        print(dp[r-1]-dp[l-2])

全部评论

相关推荐

七牛云头号黑子:人家是过度包装被看出来没过简历,你是包都不包啊兄弟
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务