Topic Link: Click to enter
First of all, it's easy to see that we actually just maintain a set of dominant groups; If you join a new person, let's start by looking at whether someone in the dominant crowd will let the person lose his or her edge, and if not, insert the person into the collection, but notice that the person's insertion may leave others with an advantage. So it is required to be able to support fast query and modify operations, and multiset can meet this requirement.
The code is as follows:
#include <iostream>#include <cstdio>#include <cstring>#include <set>using namespace STD;structpoint{intb;the elements in///set are sorted by x BOOL operator< (Constpoint& RHS)Const{returna<rhs.a| | (a==rhs.a&&b<rhs.b); }}; multiset<Point>S multiset<Point>:: Iterator it;intMain () {//freopen ("In.txt", "R", stdin); intTscanf("%d", &t); for(intCase=1; case<=t; case++) {if(case!=1)printf("\ n");printf("Case #%d:\n", case);intN,a,b;scanf("%d", &n); S.clear (); while(n--) {scanf("%d%d", &a,&b); Point p= {a, b}; it = S.lower_bound (P);/// Find the first element less than p in a red-black tree if(It==s.begin () | | (--it)->b >=b)// If p also has advantages{S.insert (P); it = S.upper_bound (P);the elements after///it will be affected. while(It!=s.end () &&it->b >=b) S.erase (it++);/// Remove the person who loses the advantage}printf("%d\n", S.size ()); } }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Application of UVA 11020 efficient Solutions+multiset