题库练习 Settlement of Guinea Pigs
← 上一题 下一题 →

A15832 | Settlement of Guinea Pigs

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Dasha loves guinea pigs very much. In this regard, she decided to settle as many guinea pigs at home as possible and developed a plan for the next $n$ days. Every day, she will either buy a new guinea pig or call a doctor to examine all her pets.

Unfortunately, the store where she was going to buy guinea pigs does not understand them. Therefore, it cannot determine their gender. Dasha can't do it either. The only one who can help is a doctor.

To keep guinea pigs, aviaries are needed. Dasha plans to buy them in the same store. Unfortunately, only one species is sold there — a double aviary. No more than two guinea pigs can live in it.

Since Dasha does not want to cause moral injury to her pets — she will not settle two guinea pigs of different genders in one aviary.

Help Dasha calculate how many aviaries in the worst case you need to buy so that you can be sure that at no moment of time do two guinea pigs of different genders live in the same aviary.

As part of this task, we believe that guinea pigs have only two genders — male and female.

输入格式

The first line of input data contains one number $t$ ( $1 \leqslant t \leqslant 10^5$ ) — the number of input data sets.

The first line of each input data set contains one number $n$ ( $1 \leqslant n \leqslant 10^5$ ) — the number of days Dasha has a plan for.

The next line contains $n$ numbers $b_1, b_2, b_3, \ldots, b_n$ ( $1 \leqslant b_i \leqslant 2$ ) — Dasha's plan. If $b_i = 1$ , then on the $i$ th day, Dasha will buy a new guinea pig. If $b_i = 2$ , then on the $i$ th day, a doctor will come to Dasha and help determine the sex of all guinea pigs that Dasha already has.

It is guaranteed that the sum of $n$ for all input data sets does not exceed $10^5$ .

输出格式

For each set of input data, output one number — the minimum number of aviaries Dasha needs to buy so that no matter what the genders of the pigs turn out to be, we can settle them so that at no point in time do two guinea pigs of different genders live together.

输入输出样例

输入 #1
6
3
1 1 1
3
2 2 2
5
1 1 1 2 1
10
1 2 1 2 1 2 1 2 1 2
20
1 2 1 1 1 1 1 2 1 2 1 2 2 1 1 1 1 1 1 1
20
2 1 1 2 1 1 2 1 2 2 1 1 1 2 2 1 1 1 1 2
输出 #1
3
0
3
4
12
9
C++ 编辑器
输入
输出