Problem p03585 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define sd(n) scanf("%d", &n)
#define sl(n) scanf("%lld", &n)
#define pd(n) printf("%d", n)
#define pl(n) printf("%lld", n)
#define sf(n) scanf("%Lf", &n)
#define pf(n) printf("%.12Lf", n)
#define psp printf(" ")
#define endc printf("\n")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 4e4 + 600;
const ld eps = 1e-13;
const ld LIM = 3e8;

ld a[maxn];
ld b[maxn];
ld c[maxn];
int occ[maxn];
int n;
ld sep;
int bit[maxn];

bool sepsort(int i, int j) {
  return ((c[i] - a[i] * sep) / b[i]) < ((c[j] - a[j] * sep) / b[j]);
}

vector<int> getseq(ld z) {
  sep = z;
  vector<int> ans;
  for (int i = 1; i <= n; i++)
    ans.pb(i);
  sort(ans.begin(), ans.end(), sepsort);

  return ans;
}

void upd(int x) {
  while (x < maxn) {
    bit[x]++;
    x += x & (-x);
  }
}

int qry(int x) {
  int ans = 0;
  while (x > 0) {
    ans += bit[x];
    x -= x & (-x);
  }
  return ans;
}

int inv(vector<int> A) {
  for (int i = 0; i < n; i++)
    A[i] = occ[A[i]];
  fill(bit, bit + maxn, 0);

  int ans = 0;

  for (int i = n - 1; i >= 0; i--) {
    ans += qry(A[i]);
    upd(A[i]);
  }

  return ans;
}

ld solve() {
  int C = (n * (n - 1) / 2) / 2;
  vector<int> S = getseq(LIM), Q;

  for (int i = 0; i < n; i++)
    occ[S[i]] = i + 1;

  ld l = -LIM, r = LIM;
  while (r - l > eps) {
    ld mid = (l + r) / 2;
    Q = getseq(mid);
    int z = inv(Q);
    if (z > C)
      l = mid;
    else
      r = mid;
  }

  return (l + r) / 2;
}

int main() {
  sd(n);
  for (int i = 1; i <= n; i++) {
    sf(a[i]);
    sf(b[i]);
    sf(c[i]);
  }

  ld mx = solve();
  for (int i = 1; i <= n; i++)
    swap(a[i], b[i]);
  ld my = solve();

  cout << setprecision(12) << mx << " " << my << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define sd(n) scanf("%d", &n)
#define sl(n) scanf("%lld", &n)
#define pd(n) printf("%d", n)
#define pl(n) printf("%lld", n)
#define sf(n) scanf("%Lf", &n)
#define pf(n) printf("%.12Lf", n)
#define psp printf(" ")
#define endc printf("\n")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 4e4 + 600;
const ld eps = 1e-10;
const ld LIM = 3e8;

ld a[maxn];
ld b[maxn];
ld c[maxn];
int occ[maxn];
int n;
ld sep;
int bit[maxn];

bool sepsort(int i, int j) {
  return ((c[i] - a[i] * sep) / b[i]) < ((c[j] - a[j] * sep) / b[j]);
}

vector<int> getseq(ld z) {
  sep = z;
  vector<int> ans;
  for (int i = 1; i <= n; i++)
    ans.pb(i);
  sort(ans.begin(), ans.end(), sepsort);

  return ans;
}

void upd(int x) {
  while (x < maxn) {
    bit[x]++;
    x += x & (-x);
  }
}

int qry(int x) {
  int ans = 0;
  while (x > 0) {
    ans += bit[x];
    x -= x & (-x);
  }
  return ans;
}

int inv(vector<int> A) {
  for (int i = 0; i < n; i++)
    A[i] = occ[A[i]];
  fill(bit, bit + maxn, 0);

  int ans = 0;

  for (int i = n - 1; i >= 0; i--) {
    ans += qry(A[i]);
    upd(A[i]);
  }

  return ans;
}

ld solve() {
  int C = (n * (n - 1) / 2) / 2;
  vector<int> S = getseq(LIM), Q;

  for (int i = 0; i < n; i++)
    occ[S[i]] = i + 1;

  ld l = -LIM, r = LIM;
  while (r - l > eps) {
    ld mid = (l + r) / 2;
    Q = getseq(mid);
    int z = inv(Q);
    if (z > C)
      l = mid;
    else
      r = mid;
  }

  return (l + r) / 2;
}

int main() {
  sd(n);
  for (int i = 1; i <= n; i++) {
    sf(a[i]);
    sf(b[i]);
    sf(c[i]);
  }

  ld mx = solve();
  for (int i = 1; i <= n; i++)
    swap(a[i], b[i]);
  ld my = solve();

  cout << setprecision(12) << mx << " " << my << endl;

  return 0;
}