- 分享
保龄球
- 2024-5-30 14:08:25 @
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct A
{
int c,t;
}a[100005];
bool cmp(A i,A j)
{
return i.c<j.c;
}
signed main()
{
int n,q,x,y,ans=0;
cin >> n;
for(int i=1;i<=n;i++)
{
cin >> a[i].c;
a[i].t=i;
}
sort(a+1,a+n+1,cmp);
cin >> q;
for(int i=1;i<=q;i++)
{
cin >> x;
int l=1,r=n;
while (l<=r)
{
int mid=(l+r)/2;
if (a[mid].c>=x)
{
ans=mid;
r=mid-1;
}
else
{
l=mid+1;
}
}
if (a[ans].c==x)
{
cout << a[ans].t << "\n";
}
else
{
cout << 0 << "\n";
}
ans=0;
}
}
//template<typename _Iterator, typename _Value>
// bool
// operator()(_Iterator __it, _Value& __val) const
// { return *__it < __val; }
// };
0 条评论
目前还没有评论...