For a given set of N integers, you were asked to find the sum of all elements in a certain range (L to R) where (1 <= L <=R <= N) where 1 represents the first number and N is the last number. For example, if we have N=5 numbers 2 31 7 9, and you were asked to find the sum from 2 to 4. Then the sum33+1+7=11. You should write a program to solve this problem for a set of multiple ranges (queries).

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 9PE
icon
Related questions
Question
Write a c++ program to solve this problem in pictures below
Lab7 - Arrays Questions
Array Queries
Problem
Submissions
Teacher solutions
e Challenge task
For a given set of N integers, you were asked
to find the sum of all elements in a certain
range (L to R) where
|(1 <= L <=R <= N) where 1 represents the
first number and N is the last number.
For example, if we have N=5 numbers 2 31
7 9, and you were asked to find the sum
from 2 to 4.
Then the sum=3+1+7=11.
You should write a program to solve this
set of multiple ranges
problem for a
(queries).
Conotreinte
Transcribed Image Text:Lab7 - Arrays Questions Array Queries Problem Submissions Teacher solutions e Challenge task For a given set of N integers, you were asked to find the sum of all elements in a certain range (L to R) where |(1 <= L <=R <= N) where 1 represents the first number and N is the last number. For example, if we have N=5 numbers 2 31 7 9, and you were asked to find the sum from 2 to 4. Then the sum=3+1+7=11. You should write a program to solve this set of multiple ranges problem for a (queries). Conotreinte
Constraints
1 <= L<=R <= N
1<= N <=10000
Q <= 1000
ali) <= 1000000000
S Input Format
Line1: 2 integers N and Q, represents tO
length of the array and the number
queries respectively
Line2: N integers represents the set of the
elements a[il's
The next Q lines are the queries where each
query has 2 integers L and R
E Output Format
O lines such that for each query you need
print the sum on a separate line
O Sample #1
Input
56
12345
13
23
55
45
15
14
Output
6
9
15
10
O Sample #2
Input
104
-5 96 -1000 23 63 12 1200 78 96 30
19
26
15
36
Output
563
-806
-823
-902
" Raise Your hand!
Transcribed Image Text:Constraints 1 <= L<=R <= N 1<= N <=10000 Q <= 1000 ali) <= 1000000000 S Input Format Line1: 2 integers N and Q, represents tO length of the array and the number queries respectively Line2: N integers represents the set of the elements a[il's The next Q lines are the queries where each query has 2 integers L and R E Output Format O lines such that for each query you need print the sum on a separate line O Sample #1 Input 56 12345 13 23 55 45 15 14 Output 6 9 15 10 O Sample #2 Input 104 -5 96 -1000 23 63 12 1200 78 96 30 19 26 15 36 Output 563 -806 -823 -902 " Raise Your hand!
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Bare Bones Programming Language
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage