CF1832C.Contrast Value

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

For an array of integers [a1,a2,…,an][a_1, a_2, \dots, a_n], let's call the value ∣a1−a2∣+∣a2−a3∣+⋯+∣an−1−an∣|a_1-a_2|+|a_2-a_3|+\cdots+|a_{n-1}-a_n| the contrast of the array. Note that the contrast of an array of size 11 is equal to 00.

You are given an array of integers aa. Your task is to build an array of bb in such a way that all the following conditions are met:

  • bb is not empty, i.e there is at least one element;
  • bb is a subsequence of aa, i.e bb can be produced by deleting some elements from aa (maybe zero);
  • the contrast of bb is equal to the contrast of aa.

What is the minimum possible size of the array bb?

对于一个整数数组 [a1,a2,…,an][a_1, a_2, \dots, a_n],我们称其**对比度(contrast)**为值 ∣a1−a2∣+∣a2−a3∣+⋯+∣an−1−an∣|a_1-a_2|+|a_2-a_3|+\cdots+|a_{n-1}-a_n|。注意:长度为 11 的数组的对比度定义为 00。

给定一个整数数组 aa。你的任务是构造一个数组 bb,使其满足以下所有条件:

  • bb 非空,即至少包含一个元素;
  • bb 是 aa 的一个子序列,即 bb 可通过从 aa 中删除若干(可能为零)个元素得到;
  • bb 的对比度等于 aa 的对比度。

问:满足上述条件的数组 bb 的最小可能长度是多少?

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤3⋅1051 \le n \le 3 \cdot 10^5) — the size of the array aa.

The second line contains nn integers a1,a2,⋅,ana_1, a_2, \cdot, a_n (0≤ai≤1090 \le a_i \le 10^9) — elements of the array itself.

The sum of nn over all test cases doesn't exceed 3⋅1053 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤3⋅1051 \le n \le 3 \cdot 10^5)—— 数组 aa 的大小。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai≤1090 \le a_i \le 10^9)—— 数组的元素。

所有测试用例的 nn 之和不超过 3⋅1053 \cdot 10^5。

输出格式

For each test case, print a single integer — the minimum possible size of the array bb.

对于每个测试用例,输出一个整数——数组 bb 的最小可能长度。

输入输出样例

  • 输入#1

    4
    5
    1 3 3 3 7
    2
    4 2
    4
    1 1 1 1
    7
    5 4 2 1 0 0 4

    输出#1

    2
    2
    1
    3

输入解题思路,AI测评打分。不知道怎么写?

首页