結構體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;
}



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM