Problem p01128 (C++) — buggy submission, verdict: Runtime Error

#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

// const ll LLINF = (1LL<<60);
// const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a <= x && x < b; }
template <typename T> T ceil(T a, T b) { return a / b + !!(a % b); }
template <class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &a) {
  out << '(' << a.first << ',' << a.second << ')';
  return out;
}
template <class T> ostream &operator<<(ostream &out, const vector<T> &a) {
  out << '[';
  REP(i, a.size()) {
    out << a[i];
    if (i != a.size() - 1)
      out << ',';
  }
  out << ']';
  return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

const double EPS = 1e-10;
const double INF = 1e12;

// point
typedef complex<double> P;
namespace std {
bool operator<(const P &a, const P &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
} // namespace std
double cross(const P &a, const P &b) { return imag(conj(a) * b); }
double dot(const P &a, const P &b) { return real(conj(a) * b); }
// line
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a);
    push_back(b);
  }
};

int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0)
    return +1; // counter clockwise
  if (cross(b, c) < 0)
    return -1; // clockwise
  if (dot(b, c) < 0)
    return +2; // c--a--b on line
  if (norm(b) < norm(c))
    return -2; // a--b--c on line
  return 0;    // a--c--b on line
}

bool intersectSS(const L &s, const L &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}

P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS)
    return m[0]; // same line
  return m[0] + B / A * (m[1] - m[0]);
}

signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int T;
  cin >> T;
  REP(_, T) {
    double ax, ay, bx, by;
    cin >> ax >> ay >> bx >> by;
    L line(P(ax, ay), P(bx, by));

    // 交点の位置とその交点が高架か地下か
    vector<pair<P, int>> po;
    int n;
    cin >> n;
    REP(i, n) {
      double xs, ys, xt, yt;
      int o, l;
      cin >> xs >> ys >> xt >> yt >> o >> l;
      L l2(P(xs, ys), P(xt, yt));
      if (intersectSS(line, l2)) {
        P c = crosspoint(line, l2);
        po.PB({c, o ^ l});
      }
    }
    sort(ALL(po));
    // cout << po << endl;
    int ret = 0;
    FOR(i, 1, po.size()) {
      if (po[i].second != po[i - 1].second)
        ret++;
    }
    cout << ret << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

// const ll LLINF = (1LL<<60);
// const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a <= x && x < b; }
template <typename T> T ceil(T a, T b) { return a / b + !!(a % b); }
template <class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &a) {
  out << '(' << a.first << ',' << a.second << ')';
  return out;
}
template <class T> ostream &operator<<(ostream &out, const vector<T> &a) {
  out << '[';
  REP(i, a.size()) {
    out << a[i];
    if (i != a.size() - 1)
      out << ',';
  }
  out << ']';
  return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

const double EPS = 1e-8;
const double INF = 1e12;

// point
typedef complex<double> P;
namespace std {
bool operator<(const P &a, const P &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
} // namespace std
double cross(const P &a, const P &b) { return imag(conj(a) * b); }
double dot(const P &a, const P &b) { return real(conj(a) * b); }
// line
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a);
    push_back(b);
  }
};

P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS)
    return m[0]; // same line
  if (abs(A) < EPS)
    assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}

signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int T;
  cin >> T;
  REP(_, T) {
    int ax, ay, bx, by;
    cin >> ax >> ay >> bx >> by;
    if (ax > bx)
      swap(ax, bx), swap(ay, by);
    L line(P(ax, ay), P(bx, by));

    // 交点の位置とその交点が高架か地下か
    vector<pair<P, int>> po;
    int n;
    cin >> n;
    REP(i, n) {
      int xs, ys, xt, yt, o, l;
      cin >> xs >> ys >> xt >> yt >> o >> l;
      L l2(P(xs, ys), P(xt, yt));
      P c = crosspoint(line, l2);
      if (ax > c.real() || c.real() > bx)
        continue;
      po.PB({c, o ^ l});
    }
    sort(ALL(po));
    // cout << po << endl;
    int ret = 0;
    FOR(i, 1, po.size()) {
      if (po[i].second != po[i - 1].second)
        ret++;
    }
    cout << ret << endl;
  }

  return 0;
}