123

123

/ 0评 / 1437次 / 0
/*
 * @Author: Gehrychiang
 * @LastEditors  : Gehrychiang
 * @Website: www.yilantingfeng.site
 * @E-mail: gehrychiang@aliyun.com
 */
#include <bits/stdc++.h>
using namespace std;
int num[1000005];
int n, q;
bool find(int k)
{
    int l = 0;
    int r = n - 1;
    int mid;
    while (l < r)
    {
        mid = (l + r) >> 1;
        if (num[mid] > k)
        {
            r = mid - 1;
        }
        else if (num[mid] < k)
        {
            l = mid + 1;
        }
        else
        {
            return true;
        }
    }
    if (l == r)
    {
        if (num[l] == k)
            return true;
        else
            return false;
    }
    else
        return false;
}
int main()
{
    while (~scanf("%d %d", &n, &q))
    {
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &num[i]);
        }
        for (int i = 0; i < q; i++)
        {
            int tmp;
            scanf("%d", &tmp);
            if (tmp < num[0] || tmp > num[n - 1])
            {
                printf("YES\n");
            }
            else if (find(tmp))
                printf("no\n");
            else
                printf("YES\n");
        }
    }
    return 0;
}

发表回复

您的电子邮箱地址不会被公开。

你好 No.65343