CF1467B.Hills And Valleys

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given a sequence of nn integers a1a_1 , a2a_2 , ..., ana_n . Let us call an index jj ( 2jn12 \le j \le {{n-1}} ) a hill if aj>aj+1a_j > a_{{j+1}} and aj>aj1a_j > a_{{j-1}} ; and let us call it a valley if aj<aj+1a_j < a_{{j+1}} and aj<aj1a_j < a_{{j-1}} .

Let us define the intimidation value of a sequence as the sum of the number of hills and the number of valleys in the sequence. You can change exactly one integer in the sequence to any number that you want, or let the sequence remain unchanged. What is the minimum intimidation value that you can achieve?

输入格式

The first line of the input contains a single integer tt ( 1t100001 \le t \le 10000 ) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn ( 1n31051 \le n \le 3\cdot10^5 ).

The second line of each test case contains nn space-separated integers a1a_1 , a2a_2 , ..., ana_n ( 1ai1091 \le a_i \le 10^9 ).

It is guaranteed that the sum of nn over all test cases does not exceed 31053\cdot10^5 .

输出格式

For each test case, print a single integer — the minimum intimidation value that you can achieve.

输入输出样例

  • 输入#1

    4
    3
    1 5 3
    5
    2 2 2 2 2
    6
    1 6 2 5 2 10
    5
    1 6 2 5 1

    输出#1

    0
    0
    1
    0

说明/提示

In the first test case, changing a2a_2 to 22 results in no hills and no valleys.

In the second test case, the best answer is just to leave the array as it is.

In the third test case, changing a3a_3 to 66 results in only one valley (at the index 55 ).

In the fourth test case, changing a3a_3 to 66 results in no hills and no valleys.

首页