50 lines
1014 B
C++
50 lines
1014 B
C++
|
#include <iostream>
|
||
|
using namespace std;
|
||
|
int a[100001];
|
||
|
void erfen(int tou, int wei, int n)
|
||
|
{
|
||
|
int now = wei - tou;
|
||
|
if (now < 0||tou>wei) {
|
||
|
cout << "-1" << endl;
|
||
|
return;
|
||
|
}
|
||
|
if (now == 0) {
|
||
|
if (a[tou+now] == n) {
|
||
|
cout << tou+now << endl;
|
||
|
return;
|
||
|
} else {
|
||
|
cout << "-1" << endl;
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
now /= 2;
|
||
|
now+=tou;
|
||
|
//cout<<tou<<" "<<wei<<" "<<now<<endl<<endl;
|
||
|
if (a[now] == n) {
|
||
|
cout << now << endl;
|
||
|
return;
|
||
|
}
|
||
|
if (n>a[now]) {
|
||
|
erfen(now + 1, wei, n);
|
||
|
return;
|
||
|
} else {
|
||
|
//cout<<"<";
|
||
|
erfen(1, now - 1, n);
|
||
|
return ;
|
||
|
}
|
||
|
}
|
||
|
int main()
|
||
|
{
|
||
|
int zong, zhao;
|
||
|
cin >> zong >> zhao;
|
||
|
for (int i = 1; i <= zong; i++) {
|
||
|
cin >> a[i];
|
||
|
}
|
||
|
for (int i = 1; i <= zhao; i++) {
|
||
|
int now;
|
||
|
cin >> now;
|
||
|
erfen(1, zong, now);
|
||
|
// cout<<now<<endl;
|
||
|
}
|
||
|
}
|