PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000101. Tổng đoạn trên mảng bất biến (Range Sum Query - Immutable)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổng đoạn trên mảng bất biến (Range Sum Query - Immutable)
Range Sum Query - Immutable
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
An immutable array of integers is indexed from zero. For each query , find the sum of the elements at indices through , inclusive.
Input
The first line contains , the array length and number of queries.
The second line contains integers .
Each of the next lines contains .
Output
Print one integer sum per query, in the given order.
Subtasks
- Subtask 1 (20 points): ; ; for all ; .
- Subtask 2 (30 points): ; ; for all ; ; .
- Subtask 3 (50 points): ; ; for all ; .
Examples
Input
6 3
-2 0 3 -5 2 -1
0 2
2 5
0 5
Output
1
-1
-3
Explanation
The six elements have indices 0 through 5. Query gives . Query gives . Query covers the entire array, with sum .