Problem p03619 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define x1 ahdhasd
#define x2 isdhfisdf
#define y1 osafoijsdgd
#define y2 sjbfdd
#define MAX 100000000

int x1, y1, x2, y2;
int n;
int ax[200005], ay[200005];
double pi;

double ct(int asli, int num) {
  double res = (double)asli * 100.0;
  res -= (double)num * 20;
  res += (double)num * pi * 5;
  return res;
}

int bit[400005];
int dp[400005];

void update(int x, int v) {
  for (++x; x < 400005; x += x & -x)
    bit[x] = max(bit[x], v);
}

int query(int x) {
  int res = 0;
  for (++x; x > 0; x -= x & -x)
    res = max(res, bit[x]);
  return res;
}

int get(vector<int> &arr) {
  vector<int> v = arr;
  sort(v.begin(), v.end());
  int a = v.size();
  v.erase(unique(v.begin(), v.end()), v.end());
  int b = v.size();
  assert(a == b);
  for (int i = 0; i < arr.size(); i++) {
    arr[i] = lower_bound(v.begin(), v.end(), arr[i]) - v.begin();
  }
  int res = 0;
  for (int i = 0; i < arr.size(); i++) {
    dp[i] = query(arr[i]) + 1;
    res = max(res, dp[i]);
    update(arr[i], dp[i]);
  }
  return res;
}

int main() {
  pi = acos((double)-1.0);

  scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &ax[i], &ay[i]);
  }

  if (x1 > x2) {
    // mirror h
    x1 = MAX - x1;
    x2 = MAX - x2;
    for (int i = 0; i < n; i++) {
      ax[i] = MAX - ax[i];
    }
  }
  if (y1 > y2) {
    // mirror v
    y1 = MAX - y1;
    y2 = MAX - y2;
    for (int i = 0; i < n; i++) {
      ay[i] = MAX - ay[i];
    }
  }
  assert(x1 <= x2 && y1 <= y2);
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    if (ax[i] < x1 || ax[i] > x2 || ay[i] < y1 || ay[i] > y2)
      continue;
    v.emplace_back(ax[i], ay[i]);
  }

  if (x1 == x2) {
    // vertikal
    if (!v.empty()) {
      double res = y2 - y1;
      res *= 100.0;
      res -= 20.0;
      res += pi * 10;
      printf("%.20lf\n", res);
    } else {
      printf("%.20lf\n", (double)((double)y2 - y1) * 100.0);
    }
    return 0;
  }

  if (y1 == y2) {
    // horizontal
    if (!v.empty()) {
      double res = x2 - x1;
      res *= 100.0;
      res -= 20.0;
      res += pi * 10;
      printf("%.20lf\n", res);
    } else {
      printf("%.20lf\n", (double)((double)x2 - x1) * 100.0);
    }
    return 0;
  }

  sort(v.begin(), v.end());
  vector<int> arr;
  for (auto i : v) {
    arr.push_back(i.second);
  }
  int aa = get(arr);
  if (aa == x2 - x1 || aa == y2 - y1)
    assert(0);
  printf("%.20lf\n", ct(y2 - y1 + x2 - x1, aa));

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define x1 ahdhasd
#define x2 isdhfisdf
#define y1 osafoijsdgd
#define y2 sjbfdd
#define MAX 100000000

int x1, y1, x2, y2;
int n;
int ax[200005], ay[200005];
double pi;

double ct(int asli, int num) {
  double res = (double)asli * 100.0;
  res -= (double)num * 20;
  res += (double)num * pi * 5;
  return res;
}

int bit[400005];
int dp[400005];

void update(int x, int v) {
  for (++x; x < 400005; x += x & -x)
    bit[x] = max(bit[x], v);
}

int query(int x) {
  int res = 0;
  for (++x; x > 0; x -= x & -x)
    res = max(res, bit[x]);
  return res;
}

int get(vector<int> &arr) {
  vector<int> v = arr;
  sort(v.begin(), v.end());
  int a = v.size();
  v.erase(unique(v.begin(), v.end()), v.end());
  int b = v.size();
  assert(a == b);
  for (int i = 0; i < arr.size(); i++) {
    arr[i] = lower_bound(v.begin(), v.end(), arr[i]) - v.begin();
  }
  int res = 0;
  for (int i = 0; i < arr.size(); i++) {
    dp[i] = query(arr[i]) + 1;
    res = max(res, dp[i]);
    update(arr[i], dp[i]);
  }
  return res;
}

int main() {
  pi = acos((double)-1.0);

  scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &ax[i], &ay[i]);
  }

  if (x1 > x2) {
    // mirror h
    x1 = MAX - x1;
    x2 = MAX - x2;
    for (int i = 0; i < n; i++) {
      ax[i] = MAX - ax[i];
    }
  }
  if (y1 > y2) {
    // mirror v
    y1 = MAX - y1;
    y2 = MAX - y2;
    for (int i = 0; i < n; i++) {
      ay[i] = MAX - ay[i];
    }
  }
  assert(x1 <= x2 && y1 <= y2);
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    if (ax[i] < x1 || ax[i] > x2 || ay[i] < y1 || ay[i] > y2)
      continue;
    v.emplace_back(ax[i], ay[i]);
  }

  if (x1 == x2) {
    // vertikal
    if (!v.empty()) {
      double res = y2 - y1;
      res *= 100.0;
      res -= 20.0;
      res += pi * 10;
      printf("%.20lf\n", res);
    } else {
      printf("%.20lf\n", (double)((double)y2 - y1) * 100.0);
    }
    return 0;
  }

  if (y1 == y2) {
    // horizontal
    if (!v.empty()) {
      double res = x2 - x1;
      res *= 100.0;
      res -= 20.0;
      res += pi * 10;
      printf("%.20lf\n", res);
    } else {
      printf("%.20lf\n", (double)((double)x2 - x1) * 100.0);
    }
    return 0;
  }

  sort(v.begin(), v.end());
  vector<int> arr;
  for (auto i : v) {
    arr.push_back(i.second);
  }
  int aa = get(arr);
  if (aa == x2 - x1 + 1 || aa == y2 - y1 + 1) {
    aa--;
    double aaa = ct(y2 - y1 + x2 - x1, aa);
    aaa -= 20.0;
    aaa += pi * 10;
    printf("%.20lf\n", aaa);
    return 0;
  }
  printf("%.20lf\n", ct(y2 - y1 + x2 - x1, aa));

  return 0;
}