audvnj @ 2023-09-02 17:54:47
#include<bits/stdc++.h>
using namespace std;
int a[99999999],b[99999999],n,m,k,k2,c,d;
int cj(int z)
{
int l=1,r=n;
while(l<r)
{
c=(l+r)/2;
if(a[c]>=b[z])r=c;
else if(a[c]<b[z])l=c+1;
}
if(l==r)
{
return l;
}
else return -1;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];k=i;
}
for(int i=1;i<=m;i++)
{
cin>>b[i];
int ans=cj(b[i]);
cout<<ans;
}
}
by gtafics @ 2023-09-02 17:58:55
把数组开小一点行吗?
by Nobelium_255 @ 2023-09-02 18:00:58
125M的空间你开2e9的数组,不炸才怪咧
by 半只蒟蒻 @ 2023-09-02 18:06:55
@audvnj 用map存
另:抓群主QwQ
by audvnj @ 2023-09-02 18:07:22
@梦魂初醒 刚刚好
by audvnj @ 2023-09-02 18:08:02
#include<bits/stdc++.h>
using namespace std;
int a[99999999],b[99999999],n,m,c;
int cj(int z)
{
int l=1,r=n;
while(l<r)
{
c=(l+r)/2;
if(a[c]>=z)r=c;
else l=c+1;
}
if(a[l]==z)
{
return l;
}
else return -1;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=m;i++)
{
cin>>b[i];
int ans=cj(b[i]);
cout<<ans<<' ';
}
}
by Nobelium_255 @ 2023-09-02 18:09:38
@audvnj 125M顶多开32,768,000的int,你这个必然空间超限,不存在“刚刚好”
by Nobelium_255 @ 2023-09-02 18:11:59
@audvnj 这边建议学习map的使用
by audvnj @ 2023-09-02 18:18:35
@梦魂初醒 过了
by 2022cxy @ 2023-09-02 18:37:52
@audvnj 群主还是那么好学
by 2022cxy @ 2023-09-02 18:38:42
自愧不如啊