Range Replace

AtCoder
IDarc206_a
Time2000ms
Memory256MB
Difficulty
You are given a sequence $A=(A_1,\ldots,A_N)$ of length $N$. You perform the following operation exactly once. * Choose a pair of integers $(L,R)$ such that $1\leq L \leq R \leq N$. Replace each of $A_L,A_{L+1},\ldots,A_R$ with $A_L$. How many different sequences are possible as $A$ after the operation? ## Constraints * All input values are integers. * $1 \leq N \leq 10^6$ * $1\leq A_i \leq N$ ## Input The input is given from Standard Input in the following format: $N$ $A_1$ $\ldots$ $A_N$ [samples]
Samples
Input #1
4
1 1 2 3
Output #1
4

The possible sequences after the operation are the following four sequences:

*   $(1,1,1,1)$
*   $(1,1,1,3)$
*   $(1,1,2,2)$
*   $(1,1,2,3)$

For example, $(1,1,1,3)$ can be obtained by performing the operation with $L=2,R=3$.
Input #2
10
2 5 6 5 2 1 7 9 7 2
Output #2
41
API Response (JSON)
{
  "problem": {
    "name": "Range Replace",
    "description": {
      "content": "You are given a sequence $A=(A_1,\\ldots,A_N)$ of length $N$. You perform the following operation exactly once. *   Choose a pair of integers $(L,R)$ such that $1\\leq L \\leq R \\leq N$. Replace each of",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc206_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a sequence $A=(A_1,\\ldots,A_N)$ of length $N$. You perform the following operation exactly once.\n\n*   Choose a pair of integers $(L,R)$ such that $1\\leq L \\leq R \\leq N$. Replace each of...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments