刚才 ABC 的 C 题求条
  • 板块学术版
  • 楼主ikunTLE
  • 当前回复11
  • 已保存回复11
  • 发布时间2024/11/30 21:40
  • 上次更新2024/12/1 02:10:49
查看原帖
刚才 ABC 的 C 题求条
890515
ikunTLE楼主2024/11/30 21:40

用的二分

#include<bits/stdc++.h>
using namespace std;
#define int long long
int read(){int x=0;char f=1,ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9')x=x10+ch-'0',ch=getchar();return xf;}
const int N=2e5+10;
struct node{
	int num,id;
	friend bool operator<(const node cmp_x,const node cmp_y){
		if(cmp_x.num!=cmp_y.num)
			return cmp_x.num<cmp_y.num;
		return cmp_x.id<cmp_y.id;
	}
}a[N];
bool operator<(const node cmp_x,int cmp_y){
	return cmp_x.num<cmp_y;
}
signed main(){
	int n=read(),m=read();
	for(int i=1;i<=n;++i)
		a[i]={read(),i};
	sort(a+1,a+n+1);
	for(int i=1;i<=m;++i){
		int x=read();
		int ans=lower_bound(a+1,a+n+1,x)-a;
		printf("%lld\n",ans);
	}
	return 0;
}
2024/11/30 21:40
加载中...