juchenglin @ 2023-05-20 14:22:46
#include<bits/stdc++.h>
using namespace std;
int s[1000005];
int n=0,m=0,q=0,mid=0,l=0,r=0,cun=-1,t=0;
int main()
{
cin>>n>>m;
for(int i=0;i<n;i++)
{
cin>>s[i];
}
for(int j=0;j<m;j++)
{
cin>>q;
l=1;
r=n;
cun=-1;
while(l<=r)
{
mid=(l+r)/2;
if(s[mid]>q)
{
r=mid-1;
cun=mid;
}
else
{
l=mid+1;
}
}
if(cun==-1)
{
cout<<-1<<" ";
continue;
}
if(s[cun]!=t)
{
cout<<-1<<" ";
continue;
}
else
{
cout<<cun<<" ";
}
}
return 0;
}
by wangcaizsr @ 2023-05-20 15:04:42
if(s[mid]>q)
改成>=
by wangcaizsr @ 2023-05-20 15:07:46
cout<<cun+1<<" ";
by wangcaizsr @ 2023-05-20 15:28:06
@juchenglin 或者不按上面的改,数组开大点
by wangcaizsr @ 2023-05-20 15:29:01
re早说呀(doge)