求助CE
  • 板块P1918 保龄球
  • 楼主胡金梁
  • 当前回复4
  • 已保存回复4
  • 发布时间2021/7/22 09:15
  • 上次更新2023/11/4 13:53:08
查看原帖
求助CE
137162
胡金梁楼主2021/7/22 09:15
/*胡金梁*/
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
#define __MY_TEST__ 0
struct node
{
	int first,second;
	bool operator <(const node &other) const
	{
		return first<other.first;
	}
}a[100005];
signed main(){
#if __MY_TEST__
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].first;
		a[i].second=i;
	}
	sort(a+1,a+n+1);
	int m;
	cin>>m;
	for(int i=1;i<=m;i++)
	{
		int s;
		cin>>s;
		int l=1,r=n;
		bool flag=0;
		while(l<=r)
		{
			int mid=(l+r)>>1;
			if(a[mid].first==s)
			{
				cout<<a[mid].second<<endl;
				flag=1;
				break;
			}
			if(a[mid].first<s)
			{
				l=mid+1;
			}
			else
			{
				r=mid-1;
			}
		}
		if(flag==0)
		{
			cout<<0<<endl;
		}
	}
#if __MY_TEST__
	fclose(stdin);
	fclose(stdout);
#endif
}
2021/7/22 09:15
加载中...