#abc354f. F - Useless for LIS

F - Useless for LIS

Score : 525525 points

问题陈述

给定一个长度为 NN 的整数序列 AA

对于每个 t=1,2,,Nt = 1, 2, \dots, N,确定 AtA_t 是否包含在 AA 的最长递增子序列中。

这里,AtA_t 包含在 AA 的最长递增子序列中当且仅当满足以下条件:

  • LLAA 的最长递增子序列的长度。存在一个严格递增的整数序列 $i = (i_1, i_2, \dots, i_L) \ (i_1 < i_2 < \dots < i_L)$,其中每个元素都在 11NN 之间(包括 11NN),满足以下所有条件:

    • Ai1<Ai2<<AiLA_{i_1} < A_{i_2} < \dots < A_{i_L}
    • 对于某个 k (1kL)k \ (1 \leq k \leq L),有 ik=ti_k = t

你将得到 TT 个测试用例;解决每一个。

什么是最长递增子序列?

一个序列 AA 的子序列是通过从 AA 中提取一些元素而不改变顺序得到的序列。

一个序列 AA 的最长递增子序列是严格递增且长度最大的子序列。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given an integer sequence AA of length NN.

For each t=1,2,,Nt = 1, 2, \dots, N, determine whether AtA_t is included in a longest increasing subsequence of AA.

Here, AtA_t is included in a longest increasing subsequence of AA if and only if the following holds:

  • Let LL be the length of a longest increasing subsequence of AA. There exists a strictly increasing integer sequence $i = (i_1, i_2, \dots, i_L) \ (i_1 < i_2 < \dots < i_L)$, where each element is between 11 and NN, inclusive, that satisfies all of the following conditions:

    • Ai1<Ai2<<AiLA_{i_1} < A_{i_2} < \dots < A_{i_L}.
    • ik=ti_k = t for some k (1kL)k \ (1 \leq k \leq L).

You are given TT test cases; solve each of them.

What is a longest increasing subsequence?

A subsequence of a sequence AA is a sequence that can be derived by extracting some elements from AA without changing the order.

A longest increasing subsequence of a sequence AA is a subsequence of AA that is strictly increasing with the greatest possible length.

Constraints

  • 1T2×1051 \leq T \leq 2 \times 10^5
  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1Ai1091 \leq A_i \leq 10^9
  • The sum of NN across all test cases is at most 2×1052 \times 10^5.

Input

The input is given from Standard Input in the following format:

TT

case1\mathrm{case}_1

case2\mathrm{case}_2

\vdots

caseT\mathrm{case}_T

Here, casei\mathrm{case_i} represents the input for the ii-th case. Each case is given in the following format:

NN

A1A_1 A2A_2 \cdots ANA_N

Output

Print the answers in the following format:

answer1\mathrm{answer}_1

answer2\mathrm{answer}_2

\vdots

answerT\mathrm{answer}_T

Here, answeri\mathrm{answer}_i represents the output for the ii-th case. For each case, let there be mm indices tt such that AtA_t is included in a longest increasing subsequence of AA, which are i1,i2,,imi_1, i_2, \dots, i_m in ascending order. Print these in the following format:

mm

i1i_1 i2i_2 \cdots imi_m

Sample Input 1

1
5
2 1 4 5 3

Sample Output 1

4
1 2 3 4

One of the longest increasing subsequences is (2,4,5)(2, 4, 5), with a length of 33. Another longest increasing subsequence is (1,4,5)(1, 4, 5). However, no longest increasing subsequence includes A5A_5.

Therefore, print 1,2,3,41, 2, 3, 4.

Sample Input 2

2
6
2 5 3 4 3 4
5
10000 1000 100 1 10

Sample Output 2

5
1 3 4 5 6
2
4 5