#abc247e. E - Max Min

E - Max Min

Score : 500500 points

问题描述

我们有一个长度为 NN 的数列 A=(A1,A2,,AN)A = (A_1, A_2, \dots, A_N) 和整数 XXYY。找出满足所有以下条件的整数对 (L,R)(L, R) 的数量。

  • 1LRN1 \leq L \leq R \leq N
  • 数列中从第 LL 项到第 RR 项的最大值是 XX,最小值是 YY

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a number sequence A=(A1,A2,,AN)A = (A_1, A_2, \dots, A_N) of length NN and integers XX and YY. Find the number of pairs of integers (L,R)(L, R) satisfying all the conditions below.

  • 1LRN1 \leq L \leq R \leq N
  • The maximum value of AL,AL+1,,ARA_L, A_{L+1}, \dots, A_R is XX, and the minimum is YY.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1Ai2×1051 \leq A_i \leq 2 \times 10^5
  • 1YX2×1051 \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:

NN XX YY

A1A_1 A2A_2 \dots ANA_N

Output

Print the answer.

Sample Input 1

4 3 1
1 2 3 1

Sample Output 1

4

44 pairs satisfy the conditions: (L,R)=(1,3),(1,4),(2,4),(3,4)(L,R)=(1,3),(1,4),(2,4),(3,4).

Sample Input 2

5 2 1
1 3 2 4 1

Sample Output 2

0

No pair (L,R)(L,R) satisfies the condition.

Sample Input 3

5 1 1
1 1 1 1 1

Sample Output 3

15

It may hold that X=YX=Y.

Sample Input 4

10 8 1
2 7 1 8 2 8 1 8 2 8

Sample Output 4

36

update @ 2024/3/10 10:35:54