Goddess of Olympos
시간 제한3초메모리 제한2048 MB
길이가 n인 기온 배열과 q개의 (x, y) 쌍이 주어질 때, 최솟값이 x이고 최댓값이 y인 부분 배열의 개수를 각 쌍마다 구한다.
문제
Mr. Tzanca Hurricane wants to go visit his goddess girlfriend who lives on Mount Olympus. When planning his trip, he knows the temperature on the mountain for consecutive days. The temperature values can be viewed as an array of integers where represents the temperature on the -th day.
Since the gasoline prices went up, he is very cautious with the gas consumption of his red Ferrari. In particular, he doesn't want to waste gas on cooling or heating. Mr. Hurricane doesn't want the temperature to be too low or too high. He has temperature ranges that he finds comfortable.
For each temperature range Mr. Hurricane gives you, he is curious how many different pairs there are such that and . Please help him figure that out.
입력
The first line of input contains two integers and ().
The second line contains integers ().
The next lines describe the queries. The -th of them contains the integers and ().
출력
The output will consist of lines, the -th line containing a single integer, the answer to the -th query.