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

Prefix minimum

Time limit: 1000 ms
Memory limit: 256 MB
Given an array $A$ of $n$ integers. There are $q$ queries, each consisting of two integers $l, r$. Calculate $A_l + \text{min}(A_l, A_{l+1}) + ... + \text{min}(A_l, A_{l+1}, ..., A_r)$. ### Input - The first line contains two positive integers $n, q$. - The second line contains $n$ integers $A_i$. - The next $q$ lines each contain two integers $l, r$. ### Output - For each query, print the answer on a separate line. ### Constraints - $1 \le n, q \le 10^5$. - $1 \le A_i \le 10^9$. - $1 \le l \le r \le n$. ### Example Input: ``` 6 3 5 3 7 2 1 4 2 4 3 6 1 3 ``` Output: ``` 8 11 11 ```
Monotonic queue
Nearest position
Subarray minimum
Peak Product
Histogram
Maximum subsequence value
Deleting digits
Electric poles
Planting flowers
Ring road
Prefix minimum
Knee surgery
Topic
Data structure
Rating 1900
Solution (1) Solution