PAS_ @ 2023-07-17 21:25:31
这是帮一个禁言的朋友问的
参考了第一篇题解的代码
题解代码能AC
这几乎可以说是从题解修改来的代码:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN=1e6+10;
int a[MAXN];
int fastread(){
int x=0,y=1;
char ch=getchar();
while (ch<'0'||ch>'9'){
if (ch=='-')
y=-1;
ch=getchar();
}
return x*y;
}
signed main(){
int n=fastread(),m=fastread();
for (int i=1;i<=n;i++){
a[i]=fastread();
}
while (m--){
int x=fastread(),ans=lower_bound(a+1,a+n+1,x)-a;
if (x!=a[ans])
cout<<"-1";
else
cout<<ans;
}
return 0;
}
WA了
orz求教
by 2011FYCCCTA @ 2023-07-17 21:28:18
空格呢?
by 2011FYCCCTA @ 2023-07-17 21:29:05
每次输出后都要有空格
by 2011FYCCCTA @ 2023-07-17 21:29:56
@PAS_
by sandwich03 @ 2023-07-17 21:31:27
我想知道你int fastread()干什么的?x一直为0。x*y也为0?
by sandwich03 @ 2023-07-17 21:33:07
@PAS_ 我是说你fastread()的返回值一直为0
by PAS_ @ 2023-07-17 21:38:00
@linzhi123 快读(虽然可能效果不大?
by PAS_ @ 2023-07-17 21:38:13
@2011FYCCCTA thx
by PAS_ @ 2023-07-17 21:47:43
@2011FYCCCTA
srds咋又WA了
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN=1e6+10;
int a[MAXN];
int fastread(){
int x=0,y=1;
char ch=getchar();
while (ch<'0'||ch>'9'){
if (ch=='-')
y=-1;
ch=getchar();
}
return x*y;
}
signed main(){
int n=fastread(),m=fastread();
for (int i=1;i<=n;i++){
a[i]=fastread();
}
while (m--){
int x=fastread(),ans=lower_bound(a+1,a+n+1,x)-a;
if (x!=a[ans])
cout<<"-1 ";
else
cout<<ans<<" ";
}
return 0;
}
by 2011FYCCCTA @ 2023-07-18 06:05:47
@PAS_ 看我楼下,你快读写错了