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的時候)
代碼如下:
努力加油a啊,(o)/~
總結
以上是生活随笔為你收集整理的Orac and Medians CodeForces - 1350D(思维)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 密室逃脱水果迷屋攻略
- 下一篇: Orac and Game of Lif