Laptop
The meaning of the title: n items, each item has two attributes ai, bi a_i, b_iai,bi, Ask how many items j, satisfy ∃ \exists∃ Articlei (i ≠ j) i ~ (i \ neq j)i (i=j )使ai ≥ aj, bi ≥ bj a_i \ geq a_j, b_i \ geq b_jai≥aj,bi≥bj
Idea: First sort one of the attributes a from large to small, then enumerate each item, and set a maximum value mx mxm x is used to storebbduring enumerationThe maximum value of b , if the current item’sbbb is less thanmx mxm x, years ++。
Simple proof: in the enumeration process, ai ≥ ai + 1 a_i \geq a_{i+1}ai≥ai+1. So, mx mxm x is the maximum value among the first i items, ifi> j, bj <mx i>j, b_j<mxi>j,bj<m x , it means that j is an item that meets the conditions.
C o d e Code Code
#include<bits/stdc++.h>
using namespace std;
struct f {
long long a, b;
} s[100010];
bool cmp(f x, f y) {
return x.a > y.a;
}
int main() {
int n;
cin >> n;
for(int i=0; i<n; i++) {
cin >> s[i].a >> s[i].b;
}
sort(s, s+n, cmp);
int mx = s[0].b, ans = 0;
for(int i=1; i<n; i++) {
if(s[i].b <= mx) ans++;
else mx = s[i].b;
}
cout << ans;
return 0;
}