题意:符合要求的星星有多少对

题解:不会做,不过看完题解........排序,二分查找..........

 

#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
 
using namespace std;
typedef long long ll;
 
struct P{
    int a,b,c;
    bool operator < (const P &rhs) const{
        if(a == rhs.a)return c>rhs.c;
        return a<rhs.a;
    }
}alp[300030];
int n;
int main() {
    cin>>n;
    for(int i=0;i<n;i++) cin>>alp[i].a>>alp[i].b>>alp[i].c;
    sort(alp,alp+n);
    multiset<int> pool;
    multiset<int>::iterator it;
    int ans = 0;
    for(int i=0;i<n;i++){
        if(alp[i].c){
            it = pool.lower_bound(alp[i].b);
            if(it!=pool.begin()){
                --it;
                pool.erase(it);
                ans+=1;
            }
        }else{
            pool.insert(alp[i].b);
        }
    }
    cout<<ans<<endl;
     
    return 0;
}