Description
神奇的土拨鼠今天又很乖的皮的玩起了鼬鼠,今天依旧是掷鼬鼠。土拨鼠忘记了自己家周围有着 n 圈的着火带。已知距离土拨鼠 r[i] (1⩽i⩽n) 的位置处有一圈着火地带。现在土拨鼠有 m次投掷,告诉你它投掷的距离 L[i] (1⩽i⩽m),问你当前投掷的鼬鼠会不会解脱 gg 掉,也就是落在着火地带上(当前仅当 L[i] == r[j] (1⩽j⩽n) 时,我们认为鼬鼠落在了着火带上)。
Input
第一行是以空格分隔的两个整数 n, m。n 表示着火带的圈数,m 表示投掷的次数。
接下来一行 n 个整数 r[i],表示距离土拨鼠家 r[i]的位置处有一圈着火带。
接下来 m 行,每行一个整数 L[i],表示土拨鼠投掷的距离(1⩽n,m⩽10^5),(1⩽r[i],L[i]⩽1e9 )
Output
输出有 mm 行,每行对于每次询问,如果鼬鼠会落在着火带上输出 GG!,否则输出 The world is so beautiful~。
Sample
Input
5 5
1 4 5 7 8
10
4
3
6
5
Output
The world is so beautiful~
GG!
The world is so beautiful~
The world is so beautiful~
GG!
#include <bits/stdc++.h>
using namespace std;
int a[1000010];
int sor(int l,int r,int k)
{
if(l<=r)
{
int mid=(l+r)/2;
if(a[mid]==k)
return mid;
else if(a[mid]>k)
return sor(l,mid-1,k);
else if(a[mid]<k)
return sor(mid+1,r,k);
}
return -1;
}
int main()
{
int n,m,k;
scanf("%d %d",&n,&m);
for(int i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
while(m--)
{
scanf("%d",&k);
if(sor(0,n-1,k)==-1)
cout<<"The world is so beautiful~"<<endl;
else
cout<<"GG!"<<endl;
}
return 0;
}