report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Prefix sum - MarisaOJ: Marisa Online Judge

Prefix sum

Time limit: 500 ms
Memory limit: 256 MB
You are given an integers array $A$ of $n$ elements and $q$ queries, each of the form $(l, r)$, calculate the sum $A_l + A_{l + 1} + ... + A_r$. ### Input - The first line contains 2 integers $n, q$. - The second line contains $n$ integers $A_i$. - Each line of the next $q$ lines contains 2 integers $l, r$, a query. ### Output - Print $q$ lines, the results of $q$ queries. ### Constraints - $1 \le n, q \le 10^5$. - $1 \le A_i \le 10^9$. ### Example Input: ``` 5 3 1 3 -2 3 4 2 3 1 4 3 5 ``` Output: ``` 1 5 5 ```
Introduction to Prefix sum
Prefix sum
Maximum subarray sum
Balance substring
Divisible by d
Subarray sum
Game on array
2D prefix sum
Stair query
Maximum sum subarray 2
Average
Ratio Substrings
Maximum submatrix sum
Maximum subarray sum 3
Manhattan distance
Minimum distance
Topic
Prefix sum
Rating 800
Solution (1) Solution