样例过了但是0分求调
查看原帖
样例过了但是0分求调
1081586
Circle_Table楼主2025/7/1 11:13

蒟蒻不是很会二分QwQ
为啥样例全过但是全都WA了吖

#include <bits/stdc++.h>
#define ll long long
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int n,q,x;
struct node{
	int s,id;
	bool friend operator < (node u,node v){
		return u.s<v.s;
	}
}a[114514];
int l,r,mid;
int main(){
	ios;cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].s;
		a[i].id=i;
	}
	sort(a+1,a+1+n);
	cin>>q;
	while(q--){
		cin>>x;
		l=1,r=n;
		while(l<r-1){
			mid=(l+r)/2;
			if(a[mid].s<x)l=mid+1;
			if(a[mid].s>=x)r=mid;
		}
		if(a[l].s!=x)cout<<"0\n";
		else cout<<a[l].id<<'\n';
	}
	return 0;
}

2025/7/1 11:13
加载中...