第一个点莫名WA
查看原帖
第一个点莫名WA
209106
ReciiZolfer楼主2021/11/18 20:55
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define en cout<<' '
int n,m,x,a[1000010];
int b[1000010];

inline int find(int l,int r){
	int mid=(l+r)>>1;
	if(a[mid]==x) return b[mid];
	if(l==r) return -1;
	if(a[mid]>x) return find(l,mid);
	else return find(mid+1,r);
}
signed main()
{
	IOS;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]==a[i-1]) b[i]=b[i-1];
		else b[i]=i;
	}
	while(m--){
		cin>>x;
		cout<<find(1,n);
		en;
	}
	return 0;
}
2021/11/18 20:55
加载中...