Uva-11020-efficient Solutions (Multiset implementation BST)

Source: Internet
Author: User
Efficient Solutions

Topic Transmission: Efficient Solutions

AC Code:

#include <map> #include <set> #include <cmath> #include <deque> #include <queue> #include & lt;stack> #include <cstdio> #include <cctype> #include <string> #include <vector> #include &  lt;cstdlib> #include <cstring> #include <iostream> #include <algorithm> #define LL Long Long #define

INF 0x7fffffff using namespace std;

int n;
    struct node {int x, y;
        Node (int _x, int _y): x (_x), Y (_y) {} node () {} BOOL operator < (const node& a) const { return x < a.x | |
    (x = = a.x && y < A.Y);

}
};
Multiset<node> s;

Multiset<node>::iterator it;
    int main () {int T;
    scanf ("%d", &t);
        for (int cas = 1; CAs <= T; cas + +) {if (CAs > 1) printf ("\ n");
        printf ("Case #%d:\n", CAs);

        scanf ("%d", &n);
        S.clear ();
            for (int i = 0; i < n; i + +) {int x, y; scanf ("%d%d", &x, &Amp;y);
            Node T = node (x, y); it = S.lower_bound (t);//Returns the position of the first element greater than or equal to t if (it = = S.begin () | |
                (--it)->y > Y) {s.insert (t);  
                it = S.upper_bound (t);//Returns the position of the first element larger than t//while (it = S.end () && it->y >= y) s.erase (it + +); for (; it! = S.end () && it->y >= y;) {S.erase (it + +);//This method can only be used to remove the successive paragraph in the set, if the it++ write outside the error, because it in the previously pointed to the value has been deleted//iterator it
        is through the + + operation to point to the latter element, so can only be deleted at the time together with + + line} printf ("%d\n", S.size ());
}} return 0;
 }

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.