Soldier Assault 1

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.