영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)
시간 제한 1초 · 메모리 제한 512 MB
Problem
There are n buildings in a row numbered 1, 2,…, n from left to right. You are standing to the left of the first building. You can see a building if it is taller than all buildings to its left.
Your task is to process q queries: If only buildings in range [a, b] existed, how many buildings would you see?
Input
The first line has two integers n and q: the number of buildings and queries.
The second line has n integers h_1, h_2, …, h_n: the heights of the buildings.
Finally, there are q lines describing the queries. Each line has two integers a and b.
Output
For each query, print one integer: the number of visible buildings.
Constraints
- 1 ≤ n ≤ 10^5
- 1 ≤ q ≤ 2 · 10^5
- 1 ≤ h_i ≤ 10^9
- 1 ≤ a ≤ b ≤ n
예제
예제 1
5 3 4 1 2 2 3 1 5 2 5 3 4
1 3 1