luogu#P9928. [NFLSPC #6] 来点不那么魔怔的题面

[NFLSPC #6] 来点不那么魔怔的题面

Problem Description

Given a permutation pp of 1n1\sim n and an integer kk, you need to find a subsequence {pi1,pi2,,pim}\{p_{i_1}, p_{i_2}, \cdots, p_{i_m}\} of pp (1i1<i2<<imn1\le i_1 < i_2 < \cdots < i_m\le n) such that:

  • There are exactly kk integers jj satisfying 1jm1\le j\le m and pijp_{i_j} is the jj-th smallest among pi1,pi2,,pimp_{i_1}, p_{i_2}, \cdots, p_{i_m}.

If there are multiple solutions, output any one of them. If there is no valid subsequence, output 1-1.

Input Format

The first line contains two integers n,kn, k.

The next line contains nn integers p1,p2,,pnp_1, p_2, \cdots, p_n, representing the given permutation.

Output Format

If there is no solution, output one line with the integer 1-1.

Otherwise, output an integer mm in the first line, the length of the subsequence. You must ensure 1mn1\le m\le n.

In the next line, output mm integers i1,i2,,imi_1, i_2, \cdots, i_m, the indices of the subsequence. You must ensure 1ijn1\le i_j\le n and ij<ij+1i_j < i_{j+1} (1j<m1\le j < m).

4 1
4 2 1 3

3
2 3 4

Hint

For all testdata, 1n1051\le n\le 10 ^ 5, 1kn1\le k\le n, and p1,p2,,pnp_1, p_2, \cdots, p_n is a permutation of 1n1\sim n.

  • Subtask 1 (1010 points): n20n\leq 20.
  • Subtask 2 (1010 points): k=2k = 2.
  • Subtask 3 (3030 points): k=3k = 3.
  • Subtask 4 (3030 points): n103n\leq 10 ^ 3.
  • Subtask 5 (2020 points): no special constraints.

Source: NFLSPC #6 D by tzc_wk

Translated by ChatGPT 5