UVA 11020 (Lower_bound of efficient Solutions-multiset)

Source: Internet
Author: User



C + + Multiset, can be re-set:

S.lower_bound () The element that points to the first ai>=k of an iterator

S.upper_bound () The element that points to the first ai>k of an iterator


The subject can be translated into: There are N point coordinates (a, B)

no point on the first plane, each time you add a point to it, ask how many points each time, not in its lower left corner (excluding this point) (x ' <x,y ' <=y| | X ' <=x,y ' <y)


If p.a<a.a| | (P.A==A.A&&P.B<A.B), the other P<a

Obviously one point does not meet the condition, and thereafter it will not meet the condition, and if it can delete B, the point in its lower left corner can also be deleted

So you can remove points from the point set that don't meet the criteria.


Suppose the current point set a1<a2< <an

There are 2 different cases:

1:p does not meet the criteria.

2:p the point in the upper right corner of the P-match condition







#include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include < functional> #include <iostream> #include <cmath> #include <cctype> #include <ctime> #include <set>using namespace std; #define for (I,n) for (int. i=1;i<=n;i++) #define FORK (i,k,n) for (int i=k;i<=n;i++) # Define REP (I,n) for (int. i=0;i<n;i++) #define ForD (I,n) for (int. i=n;i;i--) #define REPD (i,n) for (int i=n;i>=0;i--) # Define Forp (x) for (int p=pre[x];p, p=next[p]) #define FORPITER (x) for (int &p=iter[x];p; p=next[p]) #define Lson (x< <1) #define Rson ((x<<1) +1) #define MEM (a) memset (A,0,sizeof (a)), #define MEMI (a) memset (A,127,sizeof (a)); Define Memi (a) memset (A,128,sizeof (a)), #define INF (2139062143) #define F (100000007) #define MAXT (40+10) #define MAXN ( 15000+10) long long mul (long long A,long long B) {return (a*b)%F;} Long Long (long A,long long B) {return (a+b)%F;} Long Long sub (long A,long long B) {return (a-b+ (a)/f*f+f)%F;} typedef LONGLong Ll;struct point{int A, B; Point () {}point (int _a,int _b): A (_a), B (_b) {}bool operator< (const point& RHS) Const{return a<rhs.a| | (a==rhs.a&&b<rhs.b);}}; Multiset<point> s;multiset<point>::iterator it;int n;int Main () {//freopen ("uva11020.in", "R", stdin);// Freopen (". Out", "w", stdout); int t;cin>>t;for (int. t=1;t<=t;t++) {printf ("Case #%d:\n", T);cin>>n; S.clear (); while (n--) {int a,b;scanf ("%d%d", &a,&b); Point P=point (A, b); It=s.lower_bound (P); Ai>=kif (It==s.begin () | | (--it)->b>b) {S.insert (P); It=s.upper_bound (P);//ai>kwhile (It!=s.end () &&it->b >= b) S.erase ( it++);} printf ("%d\n", S.size ());} if (t^t) Putchar (' \ n ');} return 0;}







UVA 11020 (Lower_bound of efficient Solutions-multiset)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.