14 Apr PMCA Friday 19:00 Python Homework 21.04.09.
Posted at 03:55h in PMCA Friday Python CCC 0 Comments
Mr. Ken is upset because of his short height. Now, he wants to imagine himself taller. So he decided to stand in front of K pillars of different heights i.e. the jth pillar has height hi. Now to feel taller, he wanted to know how many buildings he is able to see within the range [l,r] both inclusive?
The first line contains an integer K denoting the number of pillars.
The next line contains K integers denoting the height of jth pillar.
The next line contains a single integer Q (number of queries).
Next, Q lines contain pairs l and r respectively.
For every Q queries print the number of buildings visible in the range [l, r].
Sample Input 7 5 2 3 7 9 8 11 4 0 6 1 5 2 6 3 4 Sample Output 4 4 4 2 Explanation In query 1- 5, 7, 9, 11 pillars are visible so the answer is 4. In query 2 -2, 3, 7, 9 are visible so the answer is 4.
Sorry, the comment form is closed at this time.