Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>

using namespace std;

typedef complex<double> Point;

struct Segment{ Point p1, p2; };

class C{
public:
  Point p;
  int o, l;
  double d;
  C(){}
  C(Point p, int o, int l, double d): p(p), o(o), l(l), d(d) {}
  bool operator < (const C& s) const {
    return d < s.d;
  }
};

vector<C> vec;
Point A, B;
int n, T;

const double EPS = 1e-10;

double dot(Point a, Point b){
  return real(conj(a) * b);
}

double cross(Point a, Point b){
  return imag(conj(a) * b);
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw(Point p0, Point p1, Point p2){
  Point a = p1 - p0;
  Point b = p2 - p0;
  if(cross(a, b) > EPS) return COUNTER_CLOCKWISE;
  if(cross(a, b) < -EPS) return CLOCKWISE;
  if(dot(a, b) < -EPS) return ONLINE_BACK;
  if(norm(a) < norm(b)) return ONLINE_FRONT;
  return ON_SEGMENT;
}

bool isIntersect(Point p1, Point p2, Point p3, Point p4){
  return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
	  ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}

bool isIntersect(Segment s1, Segment s2){
  return isIntersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

Point getCrossPoint(Segment s1, Segment s2){
  assert(isIntersect(s1, s2));
  Point base = s2.p2 - s2.p1;
  double d1 = abs(cross(base, s1.p1 - s2.p1));
  double d2 = abs(cross(base, s1.p2 - s2.p1));
  double t = d1 / (d1 + d2);
  return s1.p1 + (s1.p2 - s1.p1) * t;
}



main(){
  cin >> T;
  while(T--){
    vec.clear();
    cin >> A.real() >> A.imag() >> B.real() >> B.imag();
    cin >> n;
    for(int i=0;i<n;i++){
      Point s, t;
      int o, l;
      cin >> s.real() >> s.imag() >> t.real() >> t.imag() >> o >> l;
      Segment s1 = (Segment){A, B};
      Segment s2 = (Segment){s, t};
      if(isIntersect(s1, s2)){
        Point p = getCrossPoint(s1, s2);
        vec.push_back(C(p, o, l, abs(p-A)));
      }
    }
    sort(vec.begin(), vec.end());
    int cnt = 0;
    int p = (vec[0].o == vec[0].l ? 1 : 0);
    for(int i=0;i<vec.size();i++){
      int t = (vec[i].o == vec[i].l ? 1 : 0);
      if(p != t) cnt++;
      p = t;
    }
    cout << cnt << endl;
  }
}

Compiler output:
a.cc: In function 'Point getCrossPoint(Segment, Segment)':
a.cc:64:3: error: 'assert' was not declared in this scope
   64 |   assert(isIntersect(s1, s2));
      |   ^~~~~~
a.cc:5:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
    4 | #include <complex>
  +++ |+#include <cassert>
    5 | 
a.cc: At global scope:
a.cc:74:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   74 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:78:9: error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'double')
   78 |     cin >> A.real() >> A.imag() >> B.real() >> B.imag();
      |     ~~~ ^~ ~~~~~~~~
      |     |            |
      |     |            double
      |     std::istream {aka std::basic_istream<char>}
In file included from /usr/include/c++/14/iostream:42,
                 from a.cc:1:
/usr/include/c++/14/istream:170:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  170 |       operator>>(bool& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:170:7: note:   conversion of argument 1 would be ill-formed:
a.cc:78:18: error: cannot bind non-const lvalue reference of type 'bool&' to a value of type 'double'
   78 |     cin >> A.real() >> A.imag() >> B.real() >> B.imag();
      |            ~~~~~~^~
/usr/include/c++/14/istream:174:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match)
  174 |       operator>>(short& __n);
      |       ^~~~~~~~
/usr/include/c++/14/istream:174:7: note:   conversion of argument 1 would be ill-formed:
a.cc:78:18: error: cannot bind non-const lvalue reference of type 'short int&' to a value of type 'double'
   78 |     cin >> A.real() >> A.imag() >> B.real() >> B.imag();
      |            ~~~~~~^~
/usr/include/c++/14/istream:177:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  177 |       operator>>(unsigned short& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:177:7: note:   conversion of argument 1 would be ill-formed:
a.cc:78:18: error: cannot bind non-const lvalue reference of type 'short unsigned int&' to a value of type 'double'
   78 |     cin >> A.real() >> A.imag() >> B.real() >> B.imag();
      |            ~~~~~~^~
/usr/include/c++/14/istream:181:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match)
  181 |       operator>>(int& __n);
      |       ^~~~~~~~
/usr/include/c++/14/istream:181:7: note:   conversion of argument 1 would be ill-formed:
a.cc:78:18: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'double'
   78 |     cin >> A.real() >> A.imag() >> B.real() >> B.imag();
      |            ~~~~~~^~
/usr/include/c++/14/istream:184:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  184 |       operator>>(unsigned int& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:184:7: note:   conversion of argument 1 would be ill-formed:
a.cc:78:18: error: cannot bind non-const lvalue reference of type 'unsigned int&' to a value of type 'double'
   78 |     cin >> A.real() >> A.imag() >> B.real() >> B.imag();
      |            ~~~~~~^~
/usr/include/c++/14/istream:188:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  188 |       operator>>(long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:188:7: note:   conversion of argument 1 would be ill-formed:
a.cc:78:18: error: cannot bind non-const lvalue reference of type 'long int&' to a value of type 'double'
   78 |     cin >> A.real() >> A.imag() >> B.real() >> B.imag();
      |            ~~~~~~^~
/usr/include/c++/14/istream:192:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  192 |       operator>>(unsigned long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:192:7: note:   conversion of argument 1 would be ill-formed:
a.cc:78:18: error: cannot bind non-const lvalue reference of type 'long unsigned int&' to a value of type 'double'
   78 |     cin >> A.real() >> A.imag() >> B.real() >> B.imag();
      |            ~~~~~~^~
/usr/include/c++/14/istream:199:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  199 |       operator>>(long long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:199:7: note:   conversion of argument 1 would be ill-formed:
a.cc:78:18: error: cannot bind non-const lvalue reference of type 'long long int&' to a value of type 'double'
   78 |     cin >> A.real() >> A.imag() >> B.real() >> B.imag();
      |            ~~~~~~^~
/usr/include/c++/14/istream:203:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  203 |       operator>>(unsigned long long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:203:7: note:   conversion of argument 1 would be ill-formed:
a.cc:78:18: error: cannot bind non-const lvalue reference of type 'long long unsigned int&' to a value of type 'double'
   78 |     cin >> A.real() >> A.imag() >> B.real() >> B.imag();
      |            ~~~~~~^~
/usr/include/c++/14/istream:219:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  219 |       operator>>(float& __f)
      |       ^~~~~~~~
/usr/include/c++/14/istream:219:7: note:   conversion of argument 1 would be ill-formed:
a.cc:78:18: error: cannot bind non-const lvalue reference of type 'float&' to a value of type 'double'
   78 |     cin >> A.real() >> A.imag() >> B.real() >> B.imag();
      |            ~~~~~~^~
/usr/include/c++/14/istream:223:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  223 |       operator>>(double& __f)
      |       ^~~~~~~~
/usr/include/c++/14/istream:223:7: note:   conversion of argument 1 would be ill-formed:
a.cc:78:18: error: cannot bind non-const lvalue reference of type 'double&' to an rvalue of type 'double'
   78 |     cin >> A.real() >> A.imag() >> B.real() >> B.imag();
      |            ~~~~~~^~
/usr/include/c++/14/istream:227:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  227 |       operator>>(long double& __f)
      |       ^~~~~~~~
/usr/include/c++/14/istream:227:7: note:   conversion of argument 1 would be ill-formed:
a.cc:78:18: error: cannot bind non-const lvalue reference of type 'long double&' to a value of type 'double'
   78 |     cin >> A.real() >> A.imag() >> B.real() >> B.imag();
      |            ~~~~~~^~
/usr/include/c++/14/istream:328:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]'
  328 |       operator>>(void*& __p)
      |       ^~~~~~~~
/usr/include/c++/14/istream:328:25: note:   no known conversion for argument 1 from 'double' to 'void*&'
  328 |       operator>>(void*& __p)
      |                  ~~~~~~~^~~
/usr/include/c++/14/istream:122:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__istream_type& (*)(__istream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]'
  122 |       operator>>(__istream_type& (*__pf)(__istream_type&))
      |       ^~~~~~~~
/usr/include/c++/14/istream:122:36: note:   no known conversion for argument 1 from 'double' to 'std::basic_istream<char>::__istream_type& (*)(std::basic_istream<char>::__istream_type&)' {aka 'std::basic_istream<char>& (*)(std::basic_istream<char>&)'}
  122 |       operator>>(__istream_type& (*__pf)(__istream_type&))
      |                  ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/istream:126:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>; __ios_type = std::basic_ios<char>]'
  126 |       operator>>(__ios_type& (*__pf)(__ios_type&))
      |       ^~~~~~~~
/usr/include/c++/14/istream:126:32: note:   no known conversion for argument 1 from 'double' to 'std::basic_istream<char>::__ios_type& (*)(std