一道二分的题目,我想这么做,但一直编译不行
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN=1e6+10;
struct node{
ll num,op;
};
node a[MAXN];
ll N,M;
bool cmp(node A,node b)
{
if(A.num==b.num)
return A.op<b.op;
return A.num<b.num;
}
int main()
{
scanf("%lld%lld",&N,&M);
for(ll i=1;i<=N;i++)
{
scanf("%lld",&a[i].num);
a[i].op=i;
}
sort(a+1,a+1+N,cmp);
ll q;
while(M--)
{
scanf("%lld",&q);
printf("%lld ",a[lower_bound(a+1,a+N+1,q)-a].op);
}
return 0;
}