Language: C++

#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define INF 200000000

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

struct P
{
	double x, y;
	P(double x, double y) :x(x), y(y) {}
	P() :P(0, 0) {}
	P operator+(const P& v)const
	{
		return P(x + v.x, y + v.y);
	}
	P operator-(const P& v)const
	{
		return P(x - v.x, y - v.y);
	}
	P operator*(const double v)const
	{
		return P(x*v, y*v);
	}
	bool operator==(const P& v)const
	{
		return abs(x - v.x) <= 0.0000000000001&&abs(y - v.y) <= 0.00000000000001;
	}
	bool operator!=(const P& v)const
	{
		return abs(x - v.x) > 0.0000000000001 || abs(y - v.y) > 0.00000000000001;
	}

	double dot(const P& v)const
	{
		return x*v.x + y*v.y;
	}
	double cross(const P& v)const
	{
		return x*v.y - y*v.x;
	}
	double length()const
	{
		return sqrt(x*x + y*y);
	}
	double length2()const
	{
		return x*x + y*y;
	}
	
	bool operator<(const P& v)const
	{
		return x<v.x || (x == v.x) && y < v.y;
	}
	bool operator>(const P& v)const
	{
		return x<v.x || (x == v.x) && y < v.y;
	}
};

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

P CalcCrossPoint(P p1, P p2, P p3, P p4)
{
	P p12, p13, p14, p34, p31, p32;
	p12 = p2 - p1; p13 = p3 - p1; p14 = p4 - p1; p34 = p4 - p3; p31 = p1 - p3; p32 = p2 - p3;

	double ksi, delta;

	ksi = (p14.x*p34.y - p14.y*p34.x);
	delta = (p12.x*p34.y - p12.y*p34.x);

	return p1 + p12*(ksi / delta);
}

double ConvexCut(vector<P>& points, P& p1, P& p2)
{
	P p12 = p2 - p1;
	int n = points.size();
	vector<int> side(n, INF);

	vector<P> newPoints;

	for (int i = 0; i < n; i++)
	{
		double cross = p12.cross(points[i] - p1);
		if (cross == 0)
		{
			side[i] = 0;
		}
		else if (cross > 0)
		{
			side[i] = 1;
		}
		else
		{
			side[i] = -1;
		}
		if (side[i] + side[(i + n - 1) % n] == 0)
		{
			newPoints.push_back(CalcCrossPoint(p1, p2, points[i], points[(i + n - 1) % n]));
		}
		if (side[i] >= 0)
		{
			newPoints.push_back(points[i]);
		}
	}
	if (side[0] + side[n - 1] == 0)
	{
		newPoints.push_back(CalcCrossPoint(p1, p2, points[0], points[n - 1]));
	}

	double area = 0.0;
	int m = newPoints.size();
	for (int i = 0; i < m; i++)
	{
		area += (newPoints[i].x - newPoints[(i + m - 1) % m].x)*(newPoints[i].y + newPoints[(i + m - 1) % m].y);
	}
	return abs(area) / 2.0;
}

vector<P> points;

int main()
{
	points.reserve(100);
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		double x, y;
		cin >> x >> y;
		points.push_back(P(x, y));
	}

	int q;
	cin >> q;

	for (int i = 0; i < q; i++)
	{
		double x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		printf("%.10lf\n", ConvexCut(points,P(x1, y1), P(x2, y2)));
	}
	
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:175:53: error: cannot bind non-const lvalue reference of type 'P&' to an rvalue of type 'P'
  175 |                 printf("%.10lf\n", ConvexCut(points,P(x1, y1), P(x2, y2)));
      |                                                     ^~~~~~~~~
a.cc:104:40: note:   initializing argument 2 of 'double ConvexCut(std::vector<P>&, P&, P&)'
  104 | double ConvexCut(vector<P>& points, P& p1, P& p2)
      |                                     ~~~^~