Codeforces Round 1005 (Div. 2)
F
We Be Summing
Codeforces
2600
原题
← E→
翻译中…

You are given an array $a$ of length $n$ and an integer $k$.

翻译中…

Call a non-empty array $b$ of length $m$ epic if there exists an integer $i$ where $1 \le i \lt m$ and $\min(b_1,\ldots,b_i) + \max(b_{i + 1},\ldots,b_m) = k$.

翻译中…

Count the number of epic subarrays$^{\text{∗}}$ of $a$.

翻译中…

$^{\text{∗}}$An array $a$ is a subarray of an array $b$ if $a$ can be obtained from $b$ by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

翻译中…

Input

翻译中…

The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of testcases.

翻译中…

The first line of each testcase contains integers $n$ and $k$ ($2 \le n \le 2 \cdot 10^5$; $n \lt k \lt 2 \cdot n$) — the length of the array $a$ and $k$.

翻译中…

The second line of each testcase contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1 \le a_i \le n$).

翻译中…

The sum of $n$ across all testcases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each testcase, output the number of epic contiguous subarrays of $a$.

翻译中…

Note

翻译中…

These are all the epic subarrays in the first testcase:

翻译中…
  • $[2, 3, 4, 5]$, because $\min(2, 3) + \max(4, 5) = 2 + 5 = 7$.
  • $[3, 4]$, because $\min(3) + \max(4) = 3 + 4 = 7$.
翻译中…

In the second test case, every subarray that contains at least one $6$ and at least one $7$ is epic.

翻译中…

样例

Input #1
6
5 7
1 2 3 4 5
7 13
6 6 6 6 7 7 7
6 9
4 5 6 6 5 1
5 9
5 5 4 5 5
5 6
3 3 3 3 3
6 8
4 5 4 5 4 5
Output #1
2
12
3
8
10
4
InputCopy OutputCopy
题目信息
题号
2064F
时间限制
3 s
内存限制
256 MB
标签
二分
数据结构
动态规划
双指针

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