Language: C++

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<iomanip>
#include<complex>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;
 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef stack<int> SI;
typedef queue<int> QI;
typedef list<int> LI;
typedef pair<int,int> PII;
typedef long long LL;
 
#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EMP empty()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 1000000000
#define PI  acos(-1.0)
////////////////////////////////////////////////
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)
 
/*????????????(???§??¨?)????????????*/
class Vector
{
public:
    double x,y;
    Vector(double x=0,double y=0):x(x),y(y){}
     
    Vector operator + (Vector p){return Vector(x+p.x,y+p.y);}
    Vector operator - (Vector p){return Vector(x-p.x,y-p.y);}
    Vector operator * (double a){return Vector(x*a,y*a);}
    Vector operator / (double a){return Vector(x/a,y/a);}
     
    double abs(){return sqrt(norm());}
    double norm(){return x*x+y*y;}
     
    bool operator <  (const Vector &p)const{return x!=p.x?x<p.x:y<p.y;}
    bool operator == (const Vector &p)const{return fabs(x-p.x)<EPS && fabs(y-p.y<EPS);}
};
 
/*???´???????????????*/
class Line
{
public:
    Vector p,q;
    Line(Vector p=Vector(),Vector q=Vector()):p(p),q(q){}
};
 
/*???????????????*/
class Circle
{
public:
    Vector c;
    double r;
    Circle(Vector c=Vector(),double r=0.0):c(c),r(r){}
};
 
/*?????§????????????*/
typedef vector<Vector> Polygon;
 
/*?????????????????????¢?????????????§??????*/
double dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
double cross(Vector a,Vector b){return a.x*b.y-b.x*a.y;}
 
/*???´???????????°????±*/
Vector project(Line l,Vector p)
{
    Vector base=l.q-l.p;
    double r=dot(p-l.p,base)/base.norm();
    return l.p+base*r;
}
 
/*?????????¨?????????????????????????????*/
int ccw(Vector p0,Vector p1,Vector p2)
{
    Vector a=p1-p0;
    Vector b=p2-p0;
    if(cross(a,b)>EPS)return 1;//????????¨???????
    if(cross(a,b)<-EPS)return -1;//?????¨???????
    if(dot(a,b)<-EPS)return 2;//p0?????????
    if(a.norm()<b.norm())return -2;//p1????\\
    return 0;//?????????
}
 
/*?????????????????????*/
bool intersect(Vector p0,Vector p1,Vector p2,Vector p3)
{
    return (ccw(p0,p1,p2)*ccw(p0,p1,p3)<=0&&ccw(p2,p3,p0)*ccw(p2,p3,p1)<=0);
}
 
/*???´??????¨???´????????????*/
Vector LLcross(Vector p0,Vector p1,Vector p2,Vector p3)
{
    double d1=cross(p3-p2,p0-p2);
    double d2=cross(p3-p2,p1-p3);
    return p0+(p1-p0)*(d1/(d1+d2));
}
 
/*??????¨???´????????????*/
pair<Vector,Vector> CLcross(Circle c,Line l)
{
    Vector pr=project(l,c.c);
    Vector e=(l.q-l.p)/(l.q-l.p).abs();
    double base=sqrt(c.r*c.r-(pr-c.c).norm());
    return make_pair(pr+e*base,pr-e*base);
}
 
/*??????¨????????????*/
double arg(Vector p){return atan2(p.y,p.x);}
Vector pol(double a,double r){return Vector(cos(r)*a,sin(r)*a);}
pair<Vector,Vector> CCcross(Circle c1,Circle c2)
{
    double d=(c1.c-c2.c).abs();
    double a=acos((c1.r*c1.r+d*d-c2.r*c2.r)/(2*c1.r*d));
    double t=arg(c2.c-c1.c);
    return make_pair(c1.c+pol(c1.r,t+a),c1.c+pol(c1.r,t-a));
}
 
/*?????§????????????????????????????????????*/
int contain(Polygon g,Vector p)
{
    int n=g.size();
    bool x=false;
    for(int i=0;i<n;i++)
    {
        Vector a=g[i]-p,b=g[(i+1)%n]-p;
        if(abs(cross(a,b))<EPS&&dot(a,b)<EPS)return 1;//??????
        if(a.y>b.y)swap(a,b);
        if(a.y<EPS&&EPS<b.y&&cross(a,b)>EPS)x=!x;
    }
    return (x?2:0);//?????????2?????????0
}
 
/*??????(Andrew)*/
Polygon AndrewScan(Polygon s)
{
    Polygon u,l;
    if(s.size()<3)return s;
    sort(s.begin(),s.end());
    u.push_back(s[0]);u.push_back(s[1]);
    l.push_back(s[s.size()-1]);l.push_back(s[s.size()-2]);
    for(int i=2;i<s.size();i++)
    {
        for(int n=u.size();n>=2&&ccw(u[n-2],u[n-1],s[i])>=0;n--)
        {
            u.pop_back();
        }
        u.push_back(s[i]);
    }
    for(int i=s.size()-3;i>=0;i--)
    {
        for(int n=l.size();n>=2&&ccw(l[n-2],l[n-1],s[i])>=0;n--)
        {
            l.pop_back();
        }
        l.push_back(s[i]);
    }
    reverse(l.begin(),l.end());
    for(int i=u.size()-2;i>=1;i--)l.push_back(u[i]);
    return l;
}
 
 
//cout<<fixed<<setprecision(10);
////////////////////////////////////////////////
#define BOT 0
#define LEF 1
#define RIG 2
#define TOP 3

class Endpoint
{
public:
	Vector p;
	int seg,st;
	Endpoint(){}
	Endpoint(Vector p,int seg,int st):p(p),seg(seg),st(st){}
	
	bool operator < (const Endpoint &ep)const
	{
		if(p.y==ep.p.y)
		{
			return st<ep.st;
		}
		else return p.y<ep.p.y;
	}
};

Endpoint EP[2*100000];

int manhattanIntersection(vector<Line> S)
{
	int n=S.size();
	for(int i=0,k=0;i<n;i++)
	{
		if(S[i].p1.y==S[i].p2.y)
		{
			if(S[i].p1.x>S[i].p2.x)swap(S[i].p1,S[i].p2);
		}
		else if(S[i].p1.y>S[i].p2.y)swap(S[i].p1,S[i].p2);
		
		if(S[i].p1.y==S[i].p2.y)
		{
			EP[k++]=Endpoint(S[i].p1,i,LEF);
			EP[k++]=Endpoint(S[i].p2,i,RIG);
		}
		else
		{
			EP[k++]=Endpoint(S[i].p1,i,BOT);
			EP[k++]=Endpoint(S[i].p2,i,TOP);
		}
	}
	
	sort(EP,EP+(2*n));
	
	set<int> BT;
	BT.insert(1000000001);
	int cnt=0;
	
	for(int i=0;i<2*n;i++)
	{
		if(EP[i].st==TOP)
		{
			BT.erase(EP[i].p.x);
		}
		else if(EP[i].st==BOT)
		{
			BT.insert(EP[i].p.x);
		}
		else if(EP[i].st==LEF)
		{
			set<int>::iterator b=BT.lower_bound(S[EP[i].seg].p1.x);
			set<int>::iterator e=BT.lower_bound(S[EP[i].seg].p2.x);
			cnt+=distance(b,e);
		}
	}
	return cnt;
}

int main()
{
	int n;cin>>n;
	Line a;
	vector<Line> S;
	REP(i,n)
	{
		cin>>a.p.x>>a.p.y>>a.q.x>>a.q.y;
		S.PB(a);
	}
	
	cout<<manhattanIntersection(S)<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int manhattanIntersection(std::vector<Line>)':
a.cc:223:25: error: '__gnu_cxx::__alloc_traits<std::allocator<Line>, Line>::value_type' {aka 'class Line'} has no member named 'p1'; did you mean 'p'?
  223 |                 if(S[i].p1.y==S[i].p2.y)
      |                         ^~
      |                         p
a.cc:223:36: error: '__gnu_cxx::__alloc_traits<std::allocator<Line>, Line>::value_type' {aka 'class Line'} has no member named 'p2'; did you mean 'p'?
  223 |                 if(S[i].p1.y==S[i].p2.y)
      |                                    ^~
      |                                    p
a.cc:225:33: error: '__gnu_cxx::__alloc_traits<std::allocator<Line>, Line>::value_type' {aka 'class Line'} has no member named 'p1'; did you mean 'p'?
  225 |                         if(S[i].p1.x>S[i].p2.x)swap(S[i].p1,S[i].p2);
      |                                 ^~
      |                                 p
a.cc:225:43: error: '__gnu_cxx::__alloc_traits<std::allocator<Line>, Line>::value_type' {aka 'class Line'} has no member named 'p2'; did you mean 'p'?
  225 |                         if(S[i].p1.x>S[i].p2.x)swap(S[i].p1,S[i].p2);
      |                                           ^~
      |                                           p
a.cc:225:58: error: '__gnu_cxx::__alloc_traits<std::allocator<Line>, Line>::value_type' {aka 'class Line'} has no member named 'p1'; did you mean 'p'?
  225 |                         if(S[i].p1.x>S[i].p2.x)swap(S[i].p1,S[i].p2);
      |                                                          ^~
      |                                                          p
a.cc:225:66: error: '__gnu_cxx::__alloc_traits<std::allocator<Line>, Line>::value_type' {aka 'class Line'} has no member named 'p2'; did you mean 'p'?
  225 |                         if(S[i].p1.x>S[i].p2.x)swap(S[i].p1,S[i].p2);
      |                                                                  ^~
      |                                                                  p
a.cc:227:30: error: '__gnu_cxx::__alloc_traits<std::allocator<Line>, Line>::value_type' {aka 'class Line'} has no member named 'p1'; did you mean 'p'?
  227 |                 else if(S[i].p1.y>S[i].p2.y)swap(S[i].p1,S[i].p2);
      |                              ^~
      |                              p
a.cc:227:40: error: '__gnu_cxx::__alloc_traits<std::allocator<Line>, Line>::value_type' {aka 'class Line'} has no member named 'p2'; did you mean 'p'?
  227 |                 else if(S[i].p1.y>S[i].p2.y)swap(S[i].p1,S[i].p2);
      |                                        ^~
      |                                        p
a.cc:227:55: error: '__gnu_cxx::__alloc_traits<std::allocator<Line>, Line>::value_type' {aka 'class Line'} has no member named 'p1'; did you mean 'p'?
  227 |                 else if(S[i].p1.y>S[i].p2.y)swap(S[i].p1,S[i].p2);
      |                                                       ^~
      |                                                       p
a.cc:227:63: error: '__gnu_cxx::__alloc_traits<std::allocator<Line>, Line>::value_type' {aka 'class Line'} has no member named 'p2'; did you mean 'p'?
  227 |                 else if(S[i].p1.y>S[i].p2.y)swap(S[i].p1,S[i].p2);
      |                                                               ^~
      |                                                               p
a.cc:229:25: error: '__gnu_cxx::__alloc_traits<std::allocator<Line>, Line>::value_type' {aka 'class Line'} has no member named 'p1'; did you mean 'p'?
  229 |                 if(S[i].p1.y==S[i].p2.y)
      |                         ^~
      |                         p
a.cc:229:36: error: '__gnu_cxx::__alloc_traits<std::allocator<Line>, Line>::value_type' {aka 'class Line'} has no member named 'p2'; did you mean 'p'?
  229 |                 if(S[i].p1.y==S[i].p2.y)
      |                                    ^~
      |                                    p
a.cc:231:47: error: '__gnu_cxx::__alloc_traits<std::allocator<Line>, Line>::value_type' {aka 'class Line'} has no member named 'p1'; did you mean 'p'?
  231 |                         EP[k++]=Endpoint(S[i].p1,i,LEF);
      |                                               ^~
      |                                               p
a.cc:232:47: error: '__gnu_cxx::__alloc_traits<std::allocator<Line>, Line>::value_type' {aka 'class Line'} has no member named 'p2'; did you mean 'p'?
  232 |                         EP[k++]=Endpoint(S[i].p2,i,RIG);
      |                                               ^~
      |                                               p
a.cc:236:47: error: '__gnu_cxx::__alloc_traits<std::allocator<Line>, Line>::value_type' {aka 'class Line'} has no member named 'p1'; did you mean 'p'?
  236 |                         EP[k++]=Endpoint(S[i].p1,i,BOT);
      |                                               ^~
      |                                               p
a.cc:237:47: error: '__gnu_cxx::__alloc_traits<std::allocator<Line>, Line>::value_type' {aka 'class Line'} has no member named 'p2'; did you mean 'p'?
  237 |                         EP[k++]=Endpoint(S[i].p2,i,TOP);
      |                                               ^~
      |                                               p
a.cc:259:74: error: '__gnu_cxx::__alloc_traits<std::allocator<Line>, Line>::value_type' {aka 'class Line'} has no member named 'p1'; did you mean 'p'?
  259 |                         set<int>::iterator b=BT.lower_bound(S[EP[i].seg].p1.x);
      |                                                                          ^~
      |                                                                          p
a.cc:260:74: error: '__gnu_cxx::__alloc_traits<std::allocator<Line>, Line>::value_type' {aka 'class Line'} has no member named 'p2'; did you mean 'p'?
  260 |                         set<int>::iterator e=BT.lower_bound(S[EP[i].seg].p2.x);
      |                                                                          ^~
      |                                                                          p
a.cc: In function 'int ccw(Vector, Vector, Vector)':
a.cc:110:1: warning: control reaches end of non-void function [-Wreturn-type]
  110 | }
      | ^