CF1416E.Split

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

One day, BThero decided to play around with arrays and came up with the following problem:

You are given an array aa , which consists of nn positive integers. The array is numerated 11 through nn . You execute the following procedure exactly once:

  • You create a new array bb which consists of 2n2n positive integers, where for each 1in1 \le i \le n the condition b2i1+b2i=aib_{2i-1}+b_{2i} = a_i holds. For example, for the array a=[6,8,2]a = [6, 8, 2] you can create b=[2,4,4,4,1,1]b = [2, 4, 4, 4, 1, 1] .
  • You merge consecutive equal numbers in bb . For example, b=[2,4,4,4,1,1]b = [2, 4, 4, 4, 1, 1] becomes b=[2,4,1]b = [2, 4, 1] .

Find and print the minimum possible value of b|b| (size of bb ) which can be achieved at the end of the procedure. It can be shown that under the given constraints there is at least one way to construct bb .

输入格式

The first line of the input file contains a single integer TT ( 1T51051 \le T \le 5 \cdot 10^5 ) denoting the number of test cases. The description of TT test cases follows.

The first line of each test contains a single integer nn ( 1n51051 \le n \le 5 \cdot 10^5 ).

The second line contains nn space-separated integers a1a_1 , a2a_2 , ..., ana_n ( 2ai1092 \le a_i \le 10^9 ).

It is guaranteed that n\sum{n} over all test cases does not exceed 51055 \cdot 10^5 .

输出格式

For each test case, print a single line containing one integer — the minimum possible value of b|b| .

输入输出样例

  • 输入#1

    3
    3
    6 8 2
    1
    4
    3
    5 6 6

    输出#1

    3
    1
    2
首页