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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Orac and Medians CodeForces - 1350D(思维)

發布時間:2023/12/15 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Orac and Medians CodeForces - 1350D(思维) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Slime has a sequence of positive integers a1,a2,…,an.

In one operation Orac can choose an arbitrary subsegment [l…r] of this sequence and replace all values al,al+1,…,ar to the value of median of {al,al+1,…,ar}.

In this problem, for the integer multiset s, the median of s is equal to the ?|s|+12?-th smallest number in it. For example, the median of {1,4,4,6,5} is 4, and the median of {1,7,5,8} is 5.

Slime wants Orac to make a1=a2=…=an=k using these operations.

Orac thinks that it is impossible, and he does not want to waste his time, so he decided to ask you if it is possible to satisfy the Slime’s requirement, he may ask you these questions several times.

Input
The first line of the input is a single integer t: the number of queries.

The first line of each query contains two integers n (1≤n≤100000) and k (1≤k≤109), the second line contains n positive integers a1,a2,…,an (1≤ai≤109)
The total sum of n is at most 100000.

Output
The output should contain t lines. The i-th line should be equal to ‘yes’ if it is possible to make all integers k in some number of operations or ‘no’, otherwise. You can print each letter in lowercase or uppercase.

Example
Input
5
5 3
1 5 2 6 1
1 6
6
3 2
1 2 3
4 3
3 1 2 3
10 3
1 2 3 4 5 6 7 8 9 10
Output
no
yes
yes
no
yes
Note
In the first query, Orac can’t turn all elements into 3.

In the second query, a1=6 is already satisfied.

In the third query, Orac can select the complete array and turn all elements into 2.

In the fourth query, Orac can’t turn all elements into 3.

In the fifth query, Orac can select [1,6] at first and then select [2,10].
思路:一開始腦子抽了寫了那么多判斷條件。。
仔細想想,我們只要能構造出一個kk這樣的,就可以構造出題目要求的序列。如果k和一個大于k的在一塊,也可以構造出這樣的一個序列。如果在一個長度為3的序列中,有兩個大于等于k的存在,就可以構造出這樣的一個序列。例如:606113,我們想全部構造為3.我們可以構造成666663,然后再變成333333這樣的。(特判n為1的時候)
代碼如下:

#include<bits/stdc++.h> #define ll long long using namespace std;const int maxx=1e5+100; int a[maxx]; int n,k;inline bool judge0() {for(int i=1;i<=n;i++){if(a[i]==k) {if(i-1>=1&&a[i-1]>=k) return 1;if(i+1<=n&&a[i+1]>=k) return 1;if(i-2>=1&&!((a[i-1]>k&&a[i-2]>k)||(a[i-1]<k&&a[i-2]<k))) return 1;if(i+2<=n&&!((a[i+1]>k&&a[i+2]>k)||(a[i+1]<k&&a[i+1]<k))) return 1;if(i-1>=1&&i+1<=n&&!((a[i-1]>k&&a[i+1]>k)||(a[i-1]<k&&a[i+1]<k))) return 1;}}for(int i=1;i<=n;){if(i+2>n) break;int num=0;if(a[i]>=k) num++;if(a[i+1]>=k) num++;if(a[i+2]>=k) num++;if(num>=2) return 1;i++;}return 0;}int main() {int t;scanf("%d",&t);while(t--){scanf("%d%d",&n,&k);int flag=0;for(int i=1;i<=n;i++){scanf("%d",&a[i]);if(a[i]==k) flag=1;}if(flag==0) cout<<"no"<<endl;else{int flag=0;if(judge0()) flag=1;if(flag||n==1) cout<<"yes"<<endl;else cout<<"no"<<endl;}}return 0; }

努力加油a啊,(o)/~

總結

以上是生活随笔為你收集整理的Orac and Medians CodeForces - 1350D(思维)的全部內容,希望文章能夠幫你解決所遇到的問題。

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