1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| #include <algorithm> #include <cstring> #include <iostream> #include <set> using namespace std; const int maxn = 2e5 + 50; int n, ytot, dy[maxn], lb[maxn], rb[maxn]; set<int> st;
int lowbit(int x) { return x & -x; }
void add(int bit[], int x, int v) { while (x <= n) bit[x] += v, x += lowbit(x); }
int query(int bit[], int x) { int res = 0; while (x > 0) res += bit[x], x -= lowbit(x); return res; }
struct node { int x_, y_; node(int x = 0, int y = 0) : x_(x), y_(y) {} bool operator<(node &x) { if (x.x_ != x_) return x_ < x.x_; return y_ < x.y_; } } arr[maxn]; #define ax(x) arr[x].x_ #define ay(x) arr[x].y_
void init() { int x, y; for (int i = 1; i <= n; ++i) { cin >> x >> y; arr[i] = node(x, y), dy[++ytot] = y; } sort(arr + 1, arr + 1 + n), sort(dy + 1, dy + 1 + ytot); ytot = unique(dy + 1, dy + 1 + ytot) - 1 - dy; for (int i = 1; i <= n; ++i) { y = lower_bound(dy + 1, dy + 1 + ytot, ay(i)) - dy; ay(i) = y, add(rb, y, 1); } }
void clear() { ytot = 0; memset(lb, 0, sizeof(lb)), memset(rb, 0, sizeof(rb)); st.clear(); }
void work() { int ans = INT_MIN, head = 1, tail = 1; while (head <= n) { tail = head; while (tail <= n && ax(tail) == ax(head)) add(rb, ay(tail++), -1); int Stan = INT_MAX, Ollie = INT_MIN; for (int i = head; i < tail; ++i) { int s = query(lb, ay(i) - 1) + query(rb, ytot) - query(rb, ay(i)); int o = query(lb, ytot) - query(lb, ay(i)) + query(rb, ay(i) - 1); Ollie = max(Ollie, o); if (o == Ollie) Stan = min(Stan, s); } if (Stan > ans) st.clear(), ans = Stan; if (Stan == ans) st.insert(Ollie); for (int i = head; i < tail; ++i) add(lb, ay(i), 1); head = tail; } printf("Stan: %d; Ollie:", ans); for (set<int>::iterator it = st.begin(); it != st.end(); ++it) { printf(" %d", *it); } puts(";"); }
int main() { while (cin >> n && n) init(), work(), clear(); return 0; }
|