news 2026/2/17 12:03:02

C. Contrast Value

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
C. Contrast Value

time limit per test

2 seconds

memory limit per test

256 megabytes

For an array of integers [a1,a2,…,an], let's call the value |a1−a2|+|a2−a3|+⋯+|an−1−an| the contrast of the array. Note that the contrast of an array of size 1 is equal to 0.

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

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

What is the minimum possible size of the array b?

Input

The first line contains a single integer t (1≤t≤104) — the number of test cases.

The first line of each test case contains a single integer n (1≤n≤3⋅105) — the size of the array a.

The second line contains n integers a1,a2,⋅,an (0≤ai≤109) — elements of the array itself.

The sum of n over all test cases doesn't exceed 3⋅105.

Output

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

Example

Input

Copy

4

5

1 3 3 3 7

2

4 2

4

1 1 1 1

7

5 4 2 1 0 0 4

Output

Copy

2 2 1 3

解题说明:此题是一道数学题,找规律可以发现数组元素分布最高点和最低点到两端的端点的绝对值之差与整个段的绝对值之差相等,因此只需要统计最低点和最高点的数目就行了。

#include <stdio.h> int a[300005]; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } int ans = 1; for (int i = 2, op = 0; i <= n; i++) { if (a[i] > a[i - 1] && op != 1) { ans++; op = 1; } else if (a[i] < a[i - 1] && op != -1) { ans++; op = -1; } } printf("%d\n", ans); } return 0; }
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/2/16 1:13:10

Steamless完全指南:轻松解除Steam游戏DRM保护

Steamless完全指南&#xff1a;轻松解除Steam游戏DRM保护 【免费下载链接】Steamless Steamless is a DRM remover of the SteamStub variants. The goal of Steamless is to make a single solution for unpacking all Steam DRM-packed files. Steamless aims to support as …

作者头像 李华
网站建设 2026/2/15 1:12:08

PingFangSC字体包:打造跨平台一致性的Web字体解决方案

PingFangSC字体包&#xff1a;打造跨平台一致性的Web字体解决方案 【免费下载链接】PingFangSC PingFangSC字体包文件、苹果平方字体文件&#xff0c;包含ttf和woff2格式 项目地址: https://gitcode.com/gh_mirrors/pi/PingFangSC 在当今多设备、多平台并存的Web环境中&…

作者头像 李华
网站建设 2026/2/16 6:57:38

推理LLM模型正在放弃temperature参数

temperature参数都非常熟悉&#xff0c;低温输出分布更加尖锐&#xff0c;高温更加平滑&#xff0c;可以用于是否鼓励模型探索。 但是在目前的前沿模型中&#xff0c;几乎都开始限制该参数了。 Open AI &#xff1a; 在前沿模型中&#xff0c;最早开始限制temperature参数的是O…

作者头像 李华
网站建设 2026/2/15 13:25:03

终极测试用例管理平台:AgileTC完整指南与实战技巧

终极测试用例管理平台&#xff1a;AgileTC完整指南与实战技巧 【免费下载链接】AgileTC AgileTC is an agile test case management platform 项目地址: https://gitcode.com/gh_mirrors/ag/AgileTC 在当今快速迭代的软件开发环境中&#xff0c;高效的测试用例管理已成为…

作者头像 李华
网站建设 2026/2/16 6:01:02

Qwen-Image-Lightning:秒级AI绘图,让创意不再等待

Qwen-Image-Lightning&#xff1a;秒级AI绘图&#xff0c;让创意不再等待 【免费下载链接】Qwen-Image-Lightning 项目地址: https://ai.gitcode.com/hf_mirrors/lightx2v/Qwen-Image-Lightning 你是否曾因AI绘图漫长的等待时间而错过灵感迸发的瞬间&#xff1f;当创意…

作者头像 李华
网站建设 2026/2/14 20:33:30

高效获取macOS安装文件的完整指南:跨平台解决方案揭秘

高效获取macOS安装文件的完整指南&#xff1a;跨平台解决方案揭秘 【免费下载链接】gibMacOS Py2/py3 script that can download macOS components direct from Apple 项目地址: https://gitcode.com/gh_mirrors/gi/gibMacOS 还在为macOS系统安装文件的获取而困扰吗&…

作者头像 李华