1.题目大意:给出一个序列,现定义一个区间的"中位数"为 ( l e n + 1 ) / 2 (len+1)/2 (len+1)/2(向下取整),每选定一个区间可以将这个区间的数都变成该中位数,问能否将整个序列都变成 k k k
2.首先序列中必须含有 k k k,有一个特别重要的点是,如果某次变动出现了连续的两个 k k k,那么以每两个连续的 k k k再加上另一个相邻的任意元素,即可将这个长度为 3 3 3的区间都变成k,那么不断扩散最终一定能将整个序列变为 k k k,下面就是看如何能构造出两个连续的 k k k
- 考虑当区间长度为 2 2 2时 { k , x } \{k,x\} {k,x}, x x x必须大于 k k k才能将这个区间变为 k k k
- 考虑区间长度为 3 3 3时 { k , x , y } \{k,x,y\} {k,x,y}, x x x和 y y y必须一个大于 k k k一个小于 k k k
没必要再往更长的区间考虑了,因为如果满足了长度为 2 2 2或 3 3 3即可满足更长的区间了
3.还有一个特别难想到的点是我们不一定去操作 k k k,也可以操作另外的大于 k k k的数,将整个序列不断迫近 k k k的地方都变成比 k k k大的数,如" 8 1 9 2 3 4 5 2 8~1~9~2~3~4~5~2 8 1 9 2 3 4 5 2", k = 4 k=4 k=4,那么我们对于 { 8 1 9 } \{8~1~9\} {8 1 9}直接都变成 { 9 9 9 } \{9~9~9\} {9 9 9},再不断延伸得到" 8 8 8 8 8 4 5 2 8~8~8~8~8~4~5~2 8 8 8 8 8 4 5 2"这样再扩散整个序列变成 4 4 4即可
综上:
我们只需看是否存在两个位置 i , j i,j i,j,使得 a [ i ] ≥ k & & a [ j ] ≥ k a[i] \geq k~~\&\&~~a[j] \geq k a[i]≥k && a[j]≥k且 j − i ≤ 2 j-i \leq 2 j−i≤2(前提是序列中包含 k k k)
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define lowbit(x) (x&(-x))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const double eps=1e-8;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=1e18;
const int Mod=1e9+7;
const int maxn=2e5+10;
int a[maxn];
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t,n,k;
cin>>t;
while(t--){
cin>>n>>k;
int flag=0;
for(int i=1,x;i<=n;i++){
cin>>x;
if(x==k){
a[i]=0,flag=1;
continue;
}
a[i]=x>k?1:-1;
}
if(!flag){
cout<<"no\n";
continue;
}
if(n==1){
cout<<"yes\n";
continue;
}
flag=0;
for(int i=1;i<=n;i++){
//cout<<a[i]<<endl;
if(a[i]>=0){
for(int j=i+1;j<=n && j-i<=2;j++)
if(a[j]>=0){
flag=1;
}
}
if(flag) break;
}
if(flag) cout<<"yes\n";
else cout<<"no\n";
}
return 0;
}