结构体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;
}


原文链接: https://www.cnblogs.com/xiaoxiao179/p/13195039.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    结构体lower_bound使用

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/199547

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月12日 下午8:10
下一篇 2023年2月12日 下午8:10

相关推荐