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).
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).
Chapter8: Arrays
Section: Chapter Questions
Problem 9PE
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F45ee139f-1a75-4898-8b7c-97db0c7cf92d%2F0ea268e5-5952-4f9a-b1ad-23b32f7b7c90%2F1z92xvk_processed.jpeg&w=3840&q=75)
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!](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F45ee139f-1a75-4898-8b7c-97db0c7cf92d%2F0ea268e5-5952-4f9a-b1ad-23b32f7b7c90%2Fc74df7d_processed.jpeg&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
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.Recommended textbooks for you
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage