Max Min

AtCoder
IDabc247_e
Time2000ms
Memory256MB
Difficulty
We have a number sequence $A = (A_1, A_2, \dots, A_N)$ of length $N$ and integers $X$ and $Y$. Find the number of pairs of integers $(L, R)$ satisfying all the conditions below. * $1 \leq L \leq R \leq N$ * The maximum value of $A_L, A_{L+1}, \dots, A_R$ is $X$, and the minimum is $Y$. ## Constraints * $1 \leq N \leq 2 \times 10^5$ * $1 \leq A_i \leq 2 \times 10^5$ * $1 \leq Y \leq X \leq 2 \times 10^5$ * All values in input are integers. ## Input Input is given from Standard Input in the following format: $N$ $X$ $Y$ $A_1$ $A_2$ $\dots$ $A_N$ [samples]
Samples
Input #1
4 3 1
1 2 3 1
Output #1
4

$4$ pairs satisfy the conditions: $(L,R)=(1,3),(1,4),(2,4),(3,4)$.
Input #2
5 2 1
1 3 2 4 1
Output #2
0

No pair $(L,R)$ satisfies the condition.
Input #3
5 1 1
1 1 1 1 1
Output #3
15

It may hold that $X=Y$.
Input #4
10 8 1
2 7 1 8 2 8 1 8 2 8
Output #4
36
API Response (JSON)
{
  "problem": {
    "name": "Max Min",
    "description": {
      "content": "We have a number sequence $A = (A_1, A_2, \\dots, A_N)$ of length $N$ and integers $X$ and $Y$. Find the number of pairs of integers $(L, R)$ satisfying all the conditions below. *   $1 \\leq L \\leq R ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc247_e"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "We have a number sequence $A = (A_1, A_2, \\dots, A_N)$ of length $N$ and integers $X$ and $Y$. Find the number of pairs of integers $(L, R)$ satisfying all the conditions below.\n\n*   $1 \\leq L \\leq R ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments