F - Useless for LIS Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 525525

問題文

長さ NN の整数列 AA が与えられます。

t=1,2,,Nt = 1, 2, \dots ,N について、 AtA_tAA の最長増加部分列に含まれることがあるか判定してください。

AtA_tAA の最長増加部分列に含まれることがあるとは、以下のことをいいます。

  • 最長増加部分列の長さを LL とする。各要素が 11 以上 NN 以下の単調増加な整数列 i=(i1,i2,,iL) (i1<i2<<iL)i = (i_1, i_2, \dots ,i_L) \ (i_1 < i_2 < \dots < i_L) であって以下をすべて満たすものが存在する。

    • 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 の最長増加部分列とは、 AA の狭義単調増加な部分列のうち列の長さが最大のものを指します。

制約

  • 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
  • 全てのテストケースにおける NN の総和は 2×1052 \times 10^5 以下

入力

入力は以下の形式で標準入力から与えられる。

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
\vdots
caseT\mathrm{case}_T

ここで casei\mathrm{case_i}ii 番目のケースの入力を意味する。各ケースは以下の形式で与えられる。

NN
A1A_1 A2A_2 \cdots ANA_N

出力

以下の形式で出力せよ。

answer1\mathrm{answer}_1
answer2\mathrm{answer}_2
\vdots
answerT\mathrm{answer}_T

ここで answeri\mathrm{answer}_iii 番目のケースの出力を意味する。各ケースについては、次の通りである。

AtA_tAA の最長増加部分列に含まれることがある ttmm 個存在し、昇順に i1,i2,,imi_1, i_2, \dots ,i_m であったとする。このとき、以下の形式で出力せよ。

mm
i1i_1 i2i_2 \cdots imi_m

入力例 1Copy

Copy
1
5
2 1 4 5 3

出力例 1Copy

Copy
4
1 2 3 4

最長増加部分列の 11 つは (2,4,5)(2, 4, 5) で、長さは 33 です。(1,4,5)(1, 4, 5) も最長増加部分列の 11 つです。しかし、 A5A_5 を含む最長増加部分列はありません。

よって、 1,2,3,41, 2, 3, 4 を出力します。


入力例 2Copy

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

出力例 2Copy

Copy
5
1 3 4 5 6
2
4 5

Score : 525525 points

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=(i1,i2,,iL) (i1<i2<<iL)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 1Copy

Copy
1
5
2 1 4 5 3

Sample Output 1Copy

Copy
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 2Copy

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

Sample Output 2Copy

Copy
5
1 3 4 5 6
2
4 5


2025-04-18 (Fri)
22:29:55 +00:00