QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 512 MB مجموع النقاط: 100

#9615. Domino Tiling

الإحصائيات

For a sequence of non-negative integers $a_1, \ldots, a_m$ of length $m$, consider a board with $m$ rows, where the $i$-th row has $a_i$ columns. A sequence $a$ is called "good" if there exists a way to tile the entire board using $1 \times 2$ and $2 \times 1$ dominoes.

Given a sequence of non-negative integers $b_1, \ldots, b_n$ of length $n$, find the number of pairs $(l, r)$ such that $1 \le l \le r \le n$ and the subsequence $b_l, \ldots, b_r$ is good.

Input

The first line contains a positive integer $T$, representing the number of test cases.

For each test case, the input consists of two lines:

The first line contains a positive integer $n$.

The second line contains $n$ non-negative integers $b_1, \ldots, b_n$.

Output

For each test case, output a single line containing a non-negative integer representing the answer.

Examples

Input 1

9
5
5 6 6 5 3
9
3 7 1 8 4 4 0 6 9
3
3 1 0
3
3 0 1
3
2 0 2
1
0
10
4 7 6 6 7 6 1 2 5 5
6
5 5 5 4 3 3
6
6 4 4 6 4 1

Output 1

7
22
3
1
6
1
12
7
15

Note 1

For the first test case, $b=[5,6,6,5,3]$, the valid pairs $(l, r)$ are: $(2,2)$, $(3,3)$, $(2,3)$, $(4,5)$, $(3,5)$, $(1,4)$, $(2,5)$.

Example 2

See the provided files.

Constraints

For all test cases, $1 \le T \le 100$, $1 \le n \le 5 \times 10^5$, $\sum n \le 10^6$, $0 \le b_i \le 10^9$.

  • Subtask 1 (5%): $n \le 10$.
  • Subtask 2 (20%): $n \le 100$, $\sum n \le 5 \times 10^3$.
  • Subtask 3 (20%): $\sum n \le 5 \times 10^3$.
  • Subtask 4 (20%): $\sum n \le 10^5$.
  • Subtask 5 (35%): No additional constraints.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.