#P4557. Tribal Migration and Territory Dispute

    ID: 17803 Type: Default 1000ms 256MiB

Tribal Migration and Territory Dispute

Tribal Migration and Territory Dispute

There are two tribes. The first tribe has n members and the second tribe has m members. Every member is represented by a point in a 2D plane with coordinates \( (x_i, y_i) \). A territory for a tribe is defined as all points that lie inside (or on the boundary) of any triangle (which may be degenerate into a line segment) formed by three members of that tribe. In other words, the territory of a tribe is exactly the convex hull formed by its members.

If there exists any point that belongs to both tribes' territories, the two tribes will engage in war over that point. To avoid prolonged conflict, the leader of the second tribe proposes a migration plan whereby every member of the second tribe is shifted by a vector \( (dx, dy) \). After migration, the new coordinates of a member become \( (x_i+dx, y_i+dy) \).

You are given q candidate migration vectors. For each candidate, determine whether the post-migration territories of the two tribes would still intersect (including boundaries). If they intersect, output YES (indicating war); otherwise, output NO (no war).

Note: The territory of a tribe is equivalent to the convex hull of the points representing its members. Also note that if the number of members is less than 3, the hull is defined as the set of all points on the line segment connecting the points (or the point itself), and the same intersection rules apply.

The formulas used in this problem are given in \( \LaTeX \) format. For example, a point is represented as \( (x_i, y_i) \) and a migration vector is \( (dx,dy) \).

inputFormat

The first line contains two integers \( n \) and \( m \) representing the number of members in the first and second tribe respectively.

The next \( n \) lines each contain two integers \( x_i \) and \( y_i \), representing the coordinates of the first tribe's members.

The following \( m \) lines each contain two integers representing the coordinates of the second tribe's members.

The next line contains an integer \( q \), the number of migration queries.

Each of the next \( q \) lines contains two integers \( dx \) and \( dy \), the migration vector for the second tribe.

outputFormat

For each query, output a single line. Print YES if after the migration the territories (convex hulls) of the two tribes intersect (including boundaries), and NO otherwise.

sample

3 3
0 0
0 1
1 0
3 3
3 4
4 3
2
0 0
-3 -3
NO

YES

</p>