链接:https://codeforces.ml/contest/1350/problem/D
Slime has a sequence of positive integers a1,a2,…,ana1,a2,…,an.
In one operation Orac can choose an arbitrary subsegment [l…r][l…r] of this sequence and replace all values al,al+1,…,aral,al+1,…,ar to the value of median of {al,al+1,…,ar}{al,al+1,…,ar}.
In this problem, for the integer multiset ss, the median of ss is equal to the ⌊|s|+12⌋⌊|s|+12⌋-th smallest number in it. For example, the median of {1,4,4,6,5}{1,4,4,6,5} is 44, and the median of {1,7,5,8}{1,7,5,8} is 55.
Slime wants Orac to make a1=a2=…=an=ka1=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 tt: the number of queries.
The first line of each query contains two integers n (1≤n≤100000)n (1≤n≤100000) and k (1≤k≤109)k (1≤k≤109), the second line contains nn positive integers a1,a2,…,an (1≤ai≤109)a1,a2,…,an (1≤ai≤109)
The total sum of nn is at most 100000100000.
Output
The output should contain tt lines. The ii-th line should be equal to 'yes' if it is possible to make all integers kk in some number of operations or 'no', otherwise. You can print each letter in lowercase or uppercase.
Example
input
Copy
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
Copy
no yes yes no yes
Note
In the first query, Orac can't turn all elements into 33.
In the second query, a1=6a1=6 is already satisfied.
In the third query, Orac can select the complete array and turn all elements into 22.
In the fourth query, Orac can't turn all elements into 33.
In the fifth query, Orac can select [1,6][1,6] at first and then select [2,10][2,10].
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
#include<algorithm>
using namespace std;
#define ll long long
#define lb long double
#define INF 0x3f3f3f3f
#define maxn 200010
ll n,k,l,t,x,s,min1;
ll a[200001];
ll dp[100001];
map<ll,ll>m;
void yes(void)
{
cout<<"yes"<<endl;
}
void no(void)
{
cout<<"no"<<endl;
}
int main()
{
cin>>t;
while(t--)
{
cin>>n>>k;
int flag=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(a[i]==k)
flag=1;
}
if(flag==0)
no();
else
{
if(n==1)
yes();
else if(n==2)
{
if(a[1]>a[2])
swap(a[1],a[2]);
if(a[1]==k)
yes();
else
no();
}
else
{
flag=0;
for(int i=1;i<=n;i++)
{
if(a[i]>=k)
{
if(a[i+1]>=k&&i+1<=n||(a[i+2]>=k&&i+2<=n))
{
flag=1;
break;
}
}
}
if(flag)
yes();
else
no();
}
}
}
}