P17717 「LAOI-21」Building Blocks / block
Background
Problem source: [HT-130-Div.3] Walnut CSP-J Mock Contest.
[LAOI](https://www.luogu.com.cn/team/48237) welcomes you.
Description
After finishing his magic tricks, Little Hex started playing with his building blocks again together with Little Toast.
Little Hex gathered all his blocks and arranged them in a row in **decreasing** order of beauty. After sorting, the beauty of the $i$-th block is $a_i$. Now Little Hex wants to stack all the blocks in a contiguous interval into one block tower, and invites Little Toast to admire it.
However, Little Toast has a unique taste for block towers. Little Toast computes the "strangeness value ($t$)" of the blocks in an interval $[l,r]$ as follows:
- First, Little Hex takes out the $l$-th block.
- Set $t=a_l$.
- Then, Little Hex stacks the $(l+1)$-th, $(l+2)$-th, $\cdots$, $r$-th blocks onto the current tower one by one. Suppose Little Hex is currently stacking the $i$-th block.
- Set $t\gets \lfloor\frac{\max(t,a_i)}{\min(t,a_i)}\rfloor$.
In the end, if the strangeness value $t$ is $1$, Little Toast calls this interval good. Now Little Toast wants to know: among all $1\leq l \leq r \leq n$, how many intervals are good?
#### Brief Statement
Multiple testcases. Each time you are given a **non-increasing** sequence $a$. For a non-empty interval $[l,r]$ of $a$, initially set $t=a_l$. Enumerate the index $i$ from $l+1$ to $r$, performing $t:=\lfloor\frac{\max(t,a_i)}{\min(t,a_i)}\rfloor$ each time. If $t=1$ after all operations, the interval is called good.
Find how many non-empty intervals of $a$ are good.
Input Format
**This problem contains multiple testcases.**
The first line contains a positive integer $T$, the number of testcases.
For each testcase:
- The first line contains a positive integer $n$, the length of the sequence;
- The second line contains $n$ positive integers, the sequence $a$.
Output Format
Output $T$ lines in total. For each testcase, output one integer, the answer.
Explanation/Hint
#### [Sample 1 Explanation]
- For the first testcase, the good intervals are $[1,2]$ and $[2,3]$;
- For the interval $[1,2]$, initially $t=3$. When stacking the $2$-nd block, $t\gets \lfloor\frac{\max(3,2)}{\min(3,2)}\rfloor=\lfloor\frac{3}{2}\rfloor=1$. So this interval is good.
- For the interval $[2,3]$, initially $t=2$. When stacking the $3$-rd block, $t\gets \lfloor\frac{\max(2,2)}{\min(2,2)}\rfloor=\lfloor\frac{2}{2}\rfloor=1$. So this interval is good.
- For the second testcase, it can be proved that no good interval exists.
- For the third testcase, the good intervals are $[1,2]$, $[1,4]$, $[2,3]$, $[1,5]$, $[3,4]$, $[3,5]$, $[5,5]$.
#### [Sample 3]
See block/block3.in and block/block3.ans in the contestant's directory.
This sample satisfies the constraints of testcase $1$.
#### [Sample 4]
See block/block4.in and block/block4.ans in the contestant's directory.
This sample satisfies the constraints of testcases $2,3$.
#### [Sample 5]
See block/block5.in and block/block5.ans in the contestant's directory.
This sample satisfies the constraints of testcases $4\sim 6$.
#### [Sample 6]
See block/block6.in and block/block6.ans in the contestant's directory.
This sample satisfies the constraints of testcases $7,8$.
#### [Sample 7]
See block/block7.in and block/block7.ans in the contestant's directory.
This sample satisfies the constraints of testcases $9\sim 11$.
#### [Sample 8]
See block/block8.in and block/block8.ans in the contestant's directory.
This sample satisfies the constraints of testcases $12\sim 20$.
#### [Constraints]
For all testdata, it is guaranteed that $1\le T\le 10^6$, $1\le n,\sum n \le 10^6$, $1\le a_i\le 10^9$.
For convenience, $\sum n$ below denotes the sum of $n$ over all testcases within one test point.
::cute-table{tuack}
|Testcase No.|$n,\sum n$|Special Property|
|:-:|:-:|:-:|
|$1$|$\le 5\times 10^2$|None|
|$2,3$|$\le 5\times 10^3$|None|
|$4\sim 6$|$\le 10^6$| A |
|$7,8$|^| B |
|$9\sim 11$|^| C |
|$12\sim 20$|^|None|
Special property A: for all $i(1\leq i\leq n)$, it is guaranteed that $a_i=n-i+1$.
Special property B: all $a_i$ are guaranteed to be equal.
Special property C: for all $i(1\leq i\leq n)$, it is guaranteed that $1\leq a_i\leq 20$.
Translated by QwenWork