AtCoder Grand Contest 063
B
Insert 1, 2, 3, ...
AtCoder
⌀ 1663
原题
← AC →
翻译中…

Problem Statement

翻译中…

A sequence $a = (a_1, \ldots, a_n)$ consisting of positive integers is said to be generatable when one can obtain $a$ by repeating the following operation on an empty sequence.

翻译中…
  • Operation: Choose a positive integer $k$, and insert $(1, 2, \ldots, k-1, k)$ into some position in the sequence. More formally, for a sequence $a = (a_1, \ldots, a_m)$, choose an integer $i$ such that $0\leq i\leq m$ and a positive integer $k$, and replace $a$ with $(a_1,\ldots,a_{i}, 1, 2, \ldots, k-1, k, a_{i+1}, \ldots, a_m)$.
翻译中…

For instance, $a = (1,2,1,1,2,1,3,4,2,3)$ is generatable. Here is one way to generate it:

翻译中…

$() \to (\boldsymbol{1,2}) \to (1,2,\boldsymbol{1,2,3}) \to (1,2,1,\boldsymbol{1,2,3,4},2,3) \to (1,2,1,1,2,\boldsymbol{1},3,4,2,3).$

翻译中…

翻译中…

You are given a sequence $A = (A_1, \ldots, A_N)$ consisting of positive integers. Find the number of pairs of integers $(L, R)$ such that:

翻译中…
  • $1\leq L\leq R\leq N$ and the contiguous subsequence $(A_L, \ldots, A_R)$ is generatable.
翻译中…

Constraints

翻译中…
  • $1\leq N\leq 5\times 10^5$
  • $1\leq A_i\leq N$
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
A_1 \ldots A_N

翻译中…

Output

翻译中…

Print the number of pairs of integers $(L, R)$ satisfying the conditions.

翻译中…

样例

Input #1
6
1 2 1 2 1 3
Output #1
11
Here are the $11$ sought pairs: - $(1,1), (1,2), (1,3), (1,4), (1,5), (1,6), (3,3), (3,4), (3,5), (3,6), (5,5).$
Input #2
5
1 1 1 1 1
Output #2
15
All the contiguous subsequences are generatable.
Input #3
7
1 2 1 2 1 3 4
Output #3
13
题目信息
题号
agc063_b
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。