| Contests - ACM Student Chapter - PSUT |
|---|
| Private |
| Spectator |
| Summer-training-01-Intermediate |
|---|
| Finished |
Majd Aldeen, a gemologist inspecting a chain of $$$n$$$ rocks in the Hashemite desert, observes that each rock holds a gemstone labeled with a positive integer. His favorite gemstone has label $$$K$$$. He considers a contiguous subsegment of rocks interesting if it contains at least one gemstone labeled $$$K$$$.Help Majd Aldeen count the number of interesting contiguous subsegments.
Formally, given an array $$$a$$$ of $$$n$$$ positive integers, count the number of pairs $$$(L, R)$$$ such that $$$1 \le L \le R \le n$$$ and $$$a_j = K$$$ for at least one index $$$j$$$ satisfying $$$L \le j \le R$$$.
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$K$$$ ($$$1 \leq n \leq 2\times10^5$$$ , $$$1 \leq K \leq 10^9$$$) — the length of the array and the target value.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \times 10^5$$$.
For each test case, output a single integer — the number of contiguous subsegments that contain $$$K$$$ at least once.
24 21 2 3 23 51 2 3
80
In the first test case, the array is $$$[1, 2, 3, 2]$$$ and $$$K = 2$$$. The $$$8$$$ interesting subsegments are: $$$[1, 2]$$$, $$$[2]$$$ , $$$[2, 3]$$$, $$$[1, 2, 3]$$$, $$$[2]$$$ , $$$[3, 2]$$$, $$$[2, 3, 2]$$$, and $$$[1, 2, 3, 2]$$$.
In the second test case, the array is $$$[1, 2, 3]$$$ and $$$K = 5$$$. No element equals $$$5$$$, so the answer is $$$0$$$.
| Name |
|---|

