日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Odd Sum Segments(CF-1196B)

發布時間:2025/3/17 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Odd Sum Segments(CF-1196B) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Problem Description

You are given an array?aa?consisting of?nn?integers?a1,a2,…,an. 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?kksubsegments.

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]?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].

Of course, it can be impossible to divide the initial array into exactly?kksubsegments 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.

Input

The first line contains one integer qq (1≤q≤2?1051≤q≤2?105) — 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≤k≤n≤2?105) — the number of elements in the array and the number of subsegments, respectively.

The second line of the query contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109), where aiai is the ii-th element of aa.

It is guaranteed that the sum of nn over all queries does not exceed 2?1052?105 (∑n≤2?105∑n≤2?105).

Output

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 r1, r2, ..., rk such that 1≤r1<r2<?<rk=n, where rjrj 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]. Note that rk is always n but you should print it anyway.

Examples

Input

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

Output

YES
1 3 5
NO
NO

題意:q 組詢問,每組給出 n 個數,以及一個 k,現在要將這 n 個數劃分成 k 組,使得每組的和都是奇數,若能成功劃分,輸出 YES 以及任意一種劃分方案,若不能成功劃分輸出 NO

思路:

偶數個奇數的和是偶數,奇數個奇數的和是奇數,任意個偶數的和是偶數,一個奇數與一個偶數的和,因此,要劃分為 k 組后使得每組和為奇數,需要從 n 個數中奇數的個數入手

假設 n 個數中存在 sum 個奇數,那么有 sum-(k-1) 個奇數是可以直接劃分成一個組,此時劃分了 k-1 個組,還需劃分 1 個組

這個時候,根據上面的結論,去判斷剩下的奇數個數是偶數還是奇數:

  • 如果是奇數個,說明他們的和為奇數,此時無論加上多少個偶數,結果為奇數,劃分成功
  • 如果是偶數個,說明他們的和為偶數,此時無論加上多少個偶數,結果為偶數,劃分失敗

因此,我們只需要統計 n 個數中奇數的個數,然后對 sum-(k-1) 進行 %2 判斷,即可得知是否能劃分成功

如果能劃分成功,那么需要輸出任意一組方案,只需要對 n 個數從前向后掃一遍,將 i 個數進行求和,如果和為奇數直接輸出當前位置,然后重新求和繼續劃分,直到劃分出 k 個區間

Source Program

#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #include<bitset> #define EPS 1e-9 #define PI acos(-1.0) #define INF 0x3f3f3f3f #define LL long long const int MOD = 1E9+7; const int N = 500000+5; const int dx[] = {-1,1,0,0,-1,-1,1,1}; const int dy[] = {0,0,-1,1,-1,1,-1,1}; using namespace std;LL a[N]; int main() {int q;scanf("%d",&q);while(q--) {LL n,k;scanf("%lld%lld",&n,&k);LL sum=0;for(int i=1; i<=n; i++) {scanf("%lld",&a[i]);if(a[i]%2)sum++;}if(sum<k)printf("NO\n");else{if( (sum-(k+1))%2==0 )printf("NO\n");else{printf("YES\n");if(k>1){int cnt=0;LL sum=0;for(int i=1;i<=n;i++){sum+=a[i];if(sum%2==1){cnt++;printf("%d ",i);sum=0;}if(cnt>=k-1)break;}}printf("%d\n",n);}}}return 0; }

?

總結

以上是生活随笔為你收集整理的Odd Sum Segments(CF-1196B)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。