结构体lower_bound使用

裸题:https://ac.nowcoder.com/acm/contest/5929/B

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
int n;
struct node{
	int val,id;
	bool operator < (const node &b) const{
		if(val!=b.val) 
			return val<b.val;
		else 
			return id<b.id;
	}
}a[100000+50];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i].val),a[i].id=i;
	sort(a+1,a+n+1);
	cout<<lower_bound(a+1,a+n+1,(node){-100,0})-a<<endl;
	cout<<lower_bound(a+1,a+n+1,(node){-2,0})-a<<endl;
	cout<<lower_bound(a+1,a+n+1,(node){1,0})-a<<endl;
	cout<<lower_bound(a+1,a+n+1,(node){100,0})-a<<endl;
}


posted @ 2020-06-26 14:56  特立独行的猪猪  阅读(1402)  评论(0编辑  收藏  举报