Soldier Kill (a) time limit: +Ms | Memory Limit:65535KB Difficulty:3
-
description
-
There are N soldiers under General south, numbered 1 to N, and the number of their kills is known.
The handyman is the South General's military adviser, the South General now wants to know the number m to the nth soldier's total kills, invites you to help the laborer to answer the South General.
Note that the South General may ask many questions.
-
input
-
only one set of test data
The first row is two integers n,m, where N represents the number of soldiers (1<n<1000000), M indicates the number of times the South General inquired (1<M<100000)
The following line is n integers, and AI indicates the number of soldiers killed by the number I. (0<=ai<=100) The
subsequent M-line has two integer m,n per line, indicating that the general South wants to know the total number of kills (1<=m,n<=n) of soldiers from number m to nth.
-
Output
-
output total kills for each query
sample input
-
-
5 2 3 4 4
-
sample output
-
69
#include <cstdio>
const int max=1000010;
int Sum[max];
int main ()
{
int n,q,m,n;
scanf ("%d%d", &n,&q);
for (int i=1;i<=n;++i)
{
scanf ("%d", &sum[i]);
SUM[I]+=SUM[I-1];
}
for (int i=0;i!=q;++i)
{
scanf ("%d%d", &m,&n);
printf ("%d\n", sum[n]-sum[m-1]);
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Soldier Assault 1