CF1196B.Odd Sum Segments

普及-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array aa consisting of nn integers a1,a2,…,ana_1, a_2, \dots, a_n. You want to split it into exactly kk non-empty non-intersecting subsegments such that each subsegment has odd sum (i. e. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the nn elements of the array aa must belong to exactly one of the kk subsegments.

Let's see some examples of dividing the array of length 55 into 33 subsegments (not necessarily with odd sums): [1,2,3,4,5][1, 2, 3, 4, 5] is the initial array, then all possible ways to divide it into 33 non-empty non-intersecting subsegments are described below:

  • [1],[2],[3,4,5][1], [2], [3, 4, 5];
  • [1],[2,3],[4,5][1], [2, 3], [4, 5];
  • [1],[2,3,4],[5][1], [2, 3, 4], [5];
  • [1,2],[3],[4,5][1, 2], [3], [4, 5];
  • [1,2],[3,4],[5][1, 2], [3, 4], [5];
  • [1,2,3],[4],[5][1, 2, 3], [4], [5].

Of course, it can be impossible to divide the initial array into exactly kk subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.

You have to answer qq independent queries.

给你一个由 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n 组成的数组 aa。你需要将该数组恰好划分为 kk 个非空、互不相交的子段(subsegment),使得每个子段的元素和均为奇数(即:对每个子段,属于该子段的所有元素之和为奇数)。不允许重新排列(打乱)给定数组中的元素。数组 aa 的全部 nn 个元素必须且仅能属于这 kk 个子段中的某一个。

我们来看一个将长度为 55 的数组划分为 33 个子段(不一定满足奇数和条件)的例子:[1,2,3,4,5][1, 2, 3, 4, 5] 是初始数组,所有将其划分为 33 个非空、互不相交子段的可能方式如下所示:

  • [1],[2],[3,4,5][1], [2], [3, 4, 5];
  • [1],[2,3],[4,5][1], [2, 3], [4, 5];
  • [1],[2,3,4],[5][1], [2, 3, 4], [5];
  • [1,2],[3],[4,5][1, 2], [3], [4, 5];
  • [1,2],[3,4],[5][1, 2], [3, 4], [5];
  • [1,2,3],[4],[5][1, 2, 3], [4], [5].

当然,有时无法将初始数组恰好划分为 kk 个子段,使得每个子段的元素和均为奇数。此时请输出 "NO"。否则,请输出 "YES",并给出一种可行的划分方案。输出格式详见后文说明。

你需要回答 qq 个相互独立的查询。

输入格式

The first line contains one integer qq (1≤q≤2⋅1051 \le q \le 2 \cdot 10^5) — the number of queries. Then qq queries follow.

The first line of the query contains two integers nn and kk (1≤k≤n≤2⋅1051 \le k \le n \le 2 \cdot 10^5) — the number of elements in the array and the number of subsegments, respectively.

The second line of the query contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9), where aia_i is the ii-th element of aa.

It is guaranteed that the sum of nn over all queries does not exceed 2⋅1052 \cdot 10^5 (∑n≤2⋅105\sum n \le 2 \cdot 10^5).

第一行包含一个整数 qq(1≤q≤2⋅1051 \le q \le 2 \cdot 10^5),表示查询次数。随后是 qq 组查询。

每组查询的第一行包含两个整数 nn 和 kk(1≤k≤n≤2⋅1051 \le k \le n \le 2 \cdot 10^5),分别表示数组的元素个数和子区间的个数。

每组查询的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \le a_i \le 10^9),其中 aia_i 是数组 aa 的第 ii 个元素。

保证所有查询的 nn 值之和不超过 2⋅1052 \cdot 10^5(即 ∑n≤2⋅105\sum n \le 2 \cdot 10^5)。

输出格式

For each query, print the answer to it. If it is impossible to divide the initial array into exactly kk subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The division can be represented as kk integers r1r_1, r2r_2, ..., rkr_k such that 1≤r1<r2<⋯<rk=n1 \le r_1 \lt r_2 \lt \dots \lt r_k = n, where rjr_j is the right border of the jj-th segment (the index of the last element that belongs to the jj-th segment), so the array is divided into subsegments [1;r1],[r1+1;r2],[r2+1,r3],…,[rk−1+1,n][1; r_1], [r_1 + 1; r_2], [r_2 + 1, r_3], \dots, [r_{k - 1} + 1, n]. Note that rkr_k is always nn but you should print it anyway.

对于每个查询,请输出对应答案。如果无法将初始数组恰好划分为 kk 个子段,使得每个子段的元素和均为奇数,则在第一行输出 "NO"。否则,在第一行输出 "YES",并在第二行输出一种可行的数组划分方案。该划分方案可用 kk 个整数 r1r_1, r2r_2, ..., rkr_k 表示,满足 1≤r1<r2<⋯<rk=n1 \le r_1 \lt r_2 \lt \dots \lt r_k = n,其中 rjr_j 表示第 jj 个子段的右边界(即属于第 jj 个子段的最后一个元素的下标),从而将数组划分为子段 [1;r1][1; r_1], [r1+1;r2][r_1 + 1; r_2], [r2+1,r3][r_2 + 1, r_3], …\dots, [rk−1+1,n][r_{k - 1} + 1, n]。注意:rkr_k 恒为 nn,但你仍需将其输出。

输入输出样例

  • 输入#1

    3
    5 3
    7 18 3 14 1
    5 4
    1 2 3 4 5
    6 2
    1 2 8 4 10 2

    输出#1

    YES
    1 3 5
    NO
    NO

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

首页