Logo
(追記) (追記ここまで)

19833번 - Equal Maximums 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB33191961.290%

문제

Sasha is preparing for programming contests, so he is studying data structures and corresponding problems. One common problem he has noticed is Range Maximum Query.

That problem is defined as follows. There is an array $a$ of $n$ integers: $a_1, a_2, \ldots, a_n$. One has to answer queries "find the maximum value in a range from the $i$-th element to the $j$-th one", so the problem is to calculate $\max \{a_i, a_{i+1}, \ldots, a_j\}$.

Of course, this task is not difficult for Sasha, and soon there was a very fast program that answers such queries. Looking at the answers, he has noticed that the answers for different queries are often the same.

Now Sasha is wondering, how many ways are there to choose a pair of non-overlapping ranges that have equal maximum elements.

Your task is to help Sasha. Find the number of quadruples $i,ドル $j,ドル $k,ドル $l,ドル such that 1ドル \le i \le j < k \le l \le n$ and $\max\{a_i, a_{i+1}, \ldots, a_j\} = \max\{a_k, a_{k+1}, \ldots, a_l\}$. Since that number can be quite large, you have to output it modulo 1ドル,000円,000円,007円$.

입력

The first line of input contains one integer $n$: the length of Sasha's array (2ドル \le n \le 100,000円$). The second line of input contains $n$ integers: array elements (they are positive and don't exceed 10ドル^9$).

출력

Output the number of pairs of non-overlapping ranges with equal maximums. Print it modulo 10ドル^9 + 7$.

제한

예제 입력 1

6
3 3 4 4 3 2

예제 출력 1

16

예제 입력 2

12
1 3 2 3 4 1 3 4 3 2 2 5

예제 출력 2

177

힌트

Pairs of ranges from the first sample:

$[\mathbf{3}], [\mathbf{3}], 4, 4, 3, 2$ $i=1$ $j=1$ $k=2$ $l=2$
$[\mathbf{3}], 3, 4, 4, [\mathbf{3}], 2$ $i=1$ $j=1$ $k=5$ $l=5$
$[\mathbf{3}], 3, 4, 4, [\mathbf{3}, 2$] $i=1$ $j=1$ $k=5$ $l=6$
$[\mathbf{3}, \mathbf{3}], 4, 4, [\mathbf{3}], 2$ $i=1$ $j=2$ $k=5$ $l=5$
$[\mathbf{3}, \mathbf{3}], 4, 4, [\mathbf{3}, 2]$ $i=1$ $j=2$ $k=5$ $l=6$
3,ドル [\mathbf{3}], 4, 4, [\mathbf{3}], 2$ $i=2$ $j=2$ $k=5$ $l=5$
3,ドル [\mathbf{3}], 4, 4, [\mathbf{3}, 2]$ $i=2$ $j=2$ $k=5$ $l=6$
$[3, 3, \mathbf{4}], [\mathbf{4}], 3, 2$ $i=1$ $j=3$ $k=4$ $l=4$
$[3, 3, \mathbf{4}], [\mathbf{4}, 3], 2$ $i=1$ $j=3$ $k=4$ $l=5$
$[3, 3, \mathbf{4}], [\mathbf{4}, 3, 2]$ $i=1$ $j=3$ $k=4$ $l=6$
3,ドル [3, \mathbf{4}], [\mathbf{4}], 3, 2$ $i=2$ $j=3$ $k=4$ $l=4$
3,ドル [3, \mathbf{4}], [\mathbf{4}, 3], 2$ $i=2$ $j=3$ $k=4$ $l=5$
3,ドル [3, \mathbf{4}], [\mathbf{4}, 3, 2]$ $i=2$ $j=3$ $k=4$ $l=6$
3,ドル 3, [\mathbf{4}], [\mathbf{4}], 3, 2$ $i=3$ $j=3$ $k=4$ $l=4$
3,ドル 3, [\mathbf{4}], [\mathbf{4}, 3], 2$ $i=3$ $j=3$ $k=4$ $l=5$
3,ドル 3, [\mathbf{4}], [\mathbf{4}, 3, 2]$ $i=3$ $j=3$ $k=4$ $l=6$

출처

Olympiad > Russian Olympiad in Informatics > Russia Team High School Programming Contest > Russia Team High School Programming Contest 2017 D번

(追記) (追記ここまで)

출처

대학교 대회

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

AltStyle によって変換されたページ (->オリジナル) /