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;
}