CF1468A.LaIS

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Let's call a sequence b1,b2,b3…,bk−1,bkb_1, b_2, b_3 \dots, b_{k - 1}, b_k almost increasing if $$\min(b_1, b_2) \le \min(b_2, b_3) \le \dots \le \min(b_{k - 1}, b_k).$$ In particular, any sequence with no more than two elements is almost increasing.

You are given a sequence of integers a1,a2,…,ana_1, a_2, \dots, a_n. Calculate the length of its longest almost increasing subsequence.

You'll be given tt test cases. Solve each test case independently.

Reminder: a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.

我们称一个序列 b1,b2,b3…,bk−1,bkb_1, b_2, b_3 \dots, b_{k - 1}, b_k 是近似递增的(almost increasing),如果满足

min⁡(b_1,b_2)≤min⁡(b_2,b_3)≤⋯≤min⁡(b_k−1,b_k).\min(b\_1, b\_2) \le \min(b\_2, b\_3) \le \dots \le \min(b\_{k - 1}, b\_k).

特别地,任何长度不超过两个元素的序列都是近似递增的。

给定一个整数序列 a1,a2,…,ana_1, a_2, \dots, a_n。请计算其最长近似递增子序列的长度。

你将收到 tt 组测试用例。请独立求解每组测试用例。

提示:子序列是指从原序列中删除若干元素(可为零个)后,保持剩余元素相对顺序所得到的序列。

输入格式

The first line contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of independent test cases.

The first line of each test case contains a single integer nn (2≤n≤5⋅1052 \le n \le 5 \cdot 10^5) — the length of the sequence aa.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤n1 \le a_i \le n) — the sequence itself.

It's guaranteed that the total sum of nn over all test cases doesn't exceed 5⋅1055 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000)—— 表示独立测试用例的数量。

每个测试用例的第一行包含一个整数 nn(2≤n≤5⋅1052 \le n \le 5 \cdot 10^5)—— 表示序列 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤n1 \le a_i \le n)—— 即该序列本身。

保证所有测试用例的 nn 值之和不超过 5⋅1055 \cdot 10^5。

输出格式

For each test case, print one integer — the length of the longest almost increasing subsequence.

对于每个测试用例,输出一个整数——最长近似递增子序列的长度。

输入输出样例

  • 输入#1

    3
    8
    1 2 7 3 2 1 2 3
    2
    2 1
    7
    4 1 5 2 6 3 7

    输出#1

    6
    2
    7

说明/提示

In the first test case, one of the optimal answers is subsequence 1,2,7,2,2,31, 2, 7, 2, 2, 3.

In the second and third test cases, the whole sequence aa is already almost increasing.

在第一个测试用例中,一个最优答案是子序列 1,2,7,2,2,31, 2, 7, 2, 2, 3。

在第二个和第三个测试用例中,整个序列 aa 已经几乎是递增的。

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

首页