Movatterモバイル変換


[0]ホーム

URL:


Logo

33325번 -Goddess of Olympos다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초2048 MB0000.000%

문제

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 $n$ consecutive days. The temperature values can be viewed as an array $t$ of $n$ integers where $t_i$ represents the temperature on the $i$-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 $q$ temperature ranges that he finds comfortable.

For each temperature range $(x, y)$ Mr. Hurricane gives you, he is curious how many different pairs $(\ell, r)$ there are such that $\min(t_{\ell}, t_{\ell + 1}, \ldots, t_{r}) = x$ and $\max(t_{\ell}, t_{\ell + 1}, \ldots, t_{r}) = y$. Please help him figure that out.

입력

The first line of input contains two integers $n$ and $q$ ($1 \leq n, q \leq 10^{5}$).

The second line contains $n$ integers $t_1, t_2, \ldots, t_n$ ($1 \leq t_i \leq n$).

The next $q$ lines describe the queries. The $i$-th of them contains the integers $x_i$ and $y_i$ ($1 \leq x_i \leq y_i \leq n$).

출력

The output will consist of $q$ lines, the $i$-th line containing a single integer, the answer to the $i$-th query.

제한

예제 입력 1

6 33 4 2 2 1 51 52 32 4

예제 출력 1

504

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2024 > Day 7: Farewell Contest E번

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일:contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호


[8]ページ先頭

©2009-2025 Movatter.jp