Problem p03619 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define LEN 15.707963267948966

long long xone, yone, xtwo, ytwo, N;
vector<pair<long long, long long>> xy;
vector<pair<long long, long long>> xy_tate;
vector<pair<long long, long long>> xy_yoko;
long long pat;

long long LIS(vector<long long> nums) {
  long long dp[200005];
  fill(dp, dp + nums.size(), INT_MAX);
  for (int i = 0; i < nums.size(); ++i) {
    *lower_bound(dp, dp + nums.size(), nums[i]) = nums[i];
  }
  return lower_bound(dp, dp + nums.size(), INT_MAX) - dp;
}

int main() {
  cin >> xone >> yone >> xtwo >> ytwo;
  cin >> N;

  if (xone <= xtwo) {
    if (yone <= ytwo) {
      pat = 1;
    } else {
      pat = 2;
      yone *= -1;
      ytwo *= -1;
    }
  } else {
    if (yone <= ytwo) {
      pat = 3;
      xone *= -1;
      xtwo *= -1;
    } else {
      pat = 4;
      xone *= -1;
      xtwo *= -1;
      yone *= -1;
      ytwo *= -1;
    }
  }

  for (long long i = 0; i < N; i++) {
    long long xtmp, ytmp;
    cin >> xtmp >> ytmp;
    if (pat == 1) {

    } else if (pat == 2) {
      ytmp *= -1;
    } else if (pat == 3) {
      xtmp *= -1;
    } else {
      xtmp *= -1;
      ytmp *= -1;
    }
    if (xone <= xtmp && xtmp <= xtwo && yone <= ytmp && ytmp <= ytwo) {
      xy.push_back(make_pair(xtmp, ytmp));
    }
    if (xone < xtmp && xtmp < xtwo && yone <= ytmp && ytmp <= ytwo) {
      xy_yoko.push_back(make_pair(xtmp, ytmp));
    }
    if (xone <= xtmp && xtmp <= xtwo && yone < ytmp && ytmp < ytwo) {
      xy_tate.push_back(make_pair(xtmp, ytmp));
    }
  }

  sort(xy.begin(), xy.end());
  sort(xy_yoko.begin(), xy_yoko.end());
  sort(xy_tate.begin(), xy_tate.end());

  vector<long long> lis;
  for (auto tmp : xy) {
    lis.push_back(tmp.second);
  }

  vector<long long> lis_yoko;
  for (auto tmp : xy_yoko) {
    lis_yoko.push_back(tmp.second);
  }

  vector<long long> lis_tate;
  for (auto tmp : xy_tate) {
    lis_tate.push_back(tmp.second);
  }

  if (xone == xtwo || yone == ytwo) {
    double base = (xtwo - xone) + (ytwo - yone);
    base *= 100;
    long long num = LIS(lis);
    // cout << "base = " << base << " num = " << num << endl;
    if (num == 1) {
      base -= 20;
      base += 2 * LEN;
    } else if (num == 0) {
    } else {
      return 1;
    }
    printf("%.15f\n", base);
    return 0;
  } else {
    double base = (xtwo - xone) + (ytwo - yone);
    base *= 100;
    long long num = LIS(lis);
    long long numtate = LIS(lis_tate);
    long long numyoko = LIS(lis_yoko);
    if (num - 1 <= numtate && num - 1 <= numyoko) {
      base -= 20 * num;
      base += num * LEN;
    } else {
      if (num == min(xtwo - xone + 1, ytwo - yone + 1)) {
        // have to use all
        base -= 20 * num;
        base += (num + 1) * LEN;
      } else {
        base -= 20 * num;
        base += (num)*LEN;
        // can skip one
        // base -= 20 * (num - 1);
        // base += (num - 1) * LEN;
        return 1;
      }
      // return 1;
    }
    printf("%.15f\n", base);
    return 0;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define LEN 15.707963267948966

long long xone, yone, xtwo, ytwo, N;
vector<pair<long long, long long>> xy;
vector<pair<long long, long long>> xy_tate;
vector<pair<long long, long long>> xy_yoko;
long long pat;

long long LIS(vector<long long> nums) {
  long long dp[200005];
  fill(dp, dp + nums.size(), INT_MAX);
  for (int i = 0; i < nums.size(); ++i) {
    *lower_bound(dp, dp + nums.size(), nums[i]) = nums[i];
  }
  return lower_bound(dp, dp + nums.size(), INT_MAX) - dp;
}

int main() {
  cin >> xone >> yone >> xtwo >> ytwo;
  cin >> N;

  if (xone <= xtwo) {
    if (yone <= ytwo) {
      pat = 1;
    } else {
      pat = 2;
      yone *= -1;
      ytwo *= -1;
    }
  } else {
    if (yone <= ytwo) {
      pat = 3;
      xone *= -1;
      xtwo *= -1;
    } else {
      pat = 4;
      xone *= -1;
      xtwo *= -1;
      yone *= -1;
      ytwo *= -1;
    }
  }

  for (long long i = 0; i < N; i++) {
    long long xtmp, ytmp;
    cin >> xtmp >> ytmp;
    if (pat == 1) {

    } else if (pat == 2) {
      ytmp *= -1;
    } else if (pat == 3) {
      xtmp *= -1;
    } else {
      xtmp *= -1;
      ytmp *= -1;
    }
    if (xone <= xtmp && xtmp <= xtwo && yone <= ytmp && ytmp <= ytwo) {
      xy.push_back(make_pair(xtmp, ytmp));
    }
    if (xone < xtmp && xtmp < xtwo && yone <= ytmp && ytmp <= ytwo) {
      xy_yoko.push_back(make_pair(xtmp, ytmp));
    }
    if (xone <= xtmp && xtmp <= xtwo && yone < ytmp && ytmp < ytwo) {
      xy_tate.push_back(make_pair(xtmp, ytmp));
    }
  }

  sort(xy.begin(), xy.end());
  sort(xy_yoko.begin(), xy_yoko.end());
  sort(xy_tate.begin(), xy_tate.end());

  vector<long long> lis;
  for (auto tmp : xy) {
    lis.push_back(tmp.second);
  }

  vector<long long> lis_yoko;
  for (auto tmp : xy_yoko) {
    lis_yoko.push_back(tmp.second);
  }

  vector<long long> lis_tate;
  for (auto tmp : xy_tate) {
    lis_tate.push_back(tmp.second);
  }

  if (xone == xtwo || yone == ytwo) {
    double base = (xtwo - xone) + (ytwo - yone);
    base *= 100;
    long long num = LIS(lis);
    // cout << "base = " << base << " num = " << num << endl;
    if (num == 1) {
      base -= 20;
      base += 2 * LEN;
    } else if (num == 0) {
    } else {
      return 1;
    }
    printf("%.15f\n", base);
    return 0;
  } else {
    double base = (xtwo - xone) + (ytwo - yone);
    base *= 100;
    long long num = LIS(lis);
    long long numtate = LIS(lis_tate);
    long long numyoko = LIS(lis_yoko);
    if (num - 1 <= numtate && num - 1 <= numyoko) {
      base -= 20 * num;
      base += num * LEN;
    } else {
      if (num == min(xtwo - xone + 1, ytwo - yone + 1)) {
        // have to use all
        base -= 20 * num;
        base += (num + 1) * LEN;
      } else {
        base -= 20 * num;
        base += (num)*LEN;
        // can skip one
        // base -= 20 * (num - 1);
        // base += (num - 1) * LEN;
        // return 1;
      }
      // return 1;
    }
    printf("%.15f\n", base);
    return 0;
  }
}