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