Bounty, the bug of this question (NOJ)

 
 

ball number (1)

Time Limit: 3000  ms | Memory Limit: 65535  KB
Difficulty: 3
describe
A game is popular in a certain country. The rules of the game are: in a pile of balls, each ball has an integer number i (0<=i<=100000000), the number can be repeated, now say a random integer k (0<=k<=100000100), It is judged whether the ball numbered k is in the pile of balls ("YES" if it exists, otherwise "NO"), and the one who answers first is the winner. Now there is a guy who wants to play this game, but he is lazy. He wants you to help him win.
enter
The first line has two integers m, n (0<=n<=100000, 0<=m<=1000000); m means that there are m balls in the pile, and n means that the game is played n times. Next, enter m+n integers, the first m respectively represent the number i of the m balls, and the last n respectively represent the random integer k in each game
output
output "YES" or "NO"
sample input
6 4
23 34 46 768 343 343
2 4 23 343
Sample output
NO
NO
YES
YES

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
vector< int > vec;
vector< int > vet;
void quick_sort(int left,int right)
{
	if(left>right)
	return ;
	int i=left;
	int j=right;
	int temp=vec[left];
	while(i!=j)
	{
		while(i<j && vec[j]>=temp) j--;
		while(i<j && vec[i]<=temp) i++;
		if(i<j)
		{
			swap (vec [i], vec [j]);
		}
	}
	swap(vec[i],vec[left]);
	quick_sort(left,i-1);
	quick_sort(i+1,right);
}
intmain()
{
	int n,m,a;
	cin>>m>>n;
	for(int i=0;i<m;i++)
	{
		cin>>a;
		vec.push_back(a);
	}
	quick_sort(0,m-1);
//	for(int i=0;i<m;i++)
//	{
//		cout<<vec[i]<<' ';
//	}
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a);
		vet.push_back(a);
	}
	for(int i=0;i<n;i++)
	{
			int r=lower_bound(vec.begin(),vec.end(),vet[i])-vec.begin();
			if(r>=0 && r<m)
			{
				if(vet[i]==vec[r])
				{
					cout<<"YES"<<endl;
				}
				else
				cout<<"NO"<<endl;
				continue;
			}
			else
			cout<<"YES"<<endl;
	}
	return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325917297&siteId=291194637