We are given problem: Hannibal at point (0,0) wants to shoot criminal at point (Xc, Yc). There is a wall between points (X1, Y1) and (X2, Y2). We need to determine if Hannibal can shoot the criminal, meaning presumably the line segment from (0,0) to (Xc, Yc) does NOT intersect the wall segment. The wall is a segment between two points. If the ray (or line segment?) crosses the wall, then presumably the bullet would hit the wall, so cannot shoot. So output YES if the line of sight is clear, i.e., no intersection between segment from origin to criminal and the wall segment, except possibly at endpoints? Typically, if the line passes exactly through an endpoint maybe considered blocked? We need to interpret. The sample: test case1: (1,1)-(2,2) wall, criminal (3,3). Hannibal at (0,0). The line from origin to (3,3) is the same line y=x. The wall segment from (1,1) to (2,2) lies exactly on that line between them. So the bullet would pass through the wall. So answer NO (cannot shoot). Test case2: same wall, criminal (1,1). Wait second test: "2 2 3 3 1 1": That is X1=2 Y1=2, X2=3 Y2=3, Xc=1 Yc=1. So wall from (2,2) to (3,3). Criminal at (1,1). The line from origin to (1,1) is again y=x, but wall is from (2,2) to (3,3), which is further out beyond the criminal? Actually criminal is at (1,1) which is before the wall segment along the same line. So the segment from (0,0) to (1,1) ends before the wall. So they don't intersect (except maybe at (1,1)? The criminal point is (1,1) and wall endpoints are (2,2) and (3,3). (1,1) is not on wall. So no intersection, answer YES. So clearly we need to check if the segment from origin to (Xc, Yc) intersects the segment (X1,Y1)-(X2,Y2). If they intersect (including interior intersections, overlapping?), then output NO; else YES.
Edge cases: The wall could be positioned such that it crosses the line of sight but not overlapping exactly; we must detect intersection correctly. Also if the line passes through an endpoint? For example, wall endpoint on the line of sight but maybe the bullet goes through that point; likely that would be blocked because wall is at that point. Usually wall segment includes its endpoints. So if the line of sight passes through an endpoint, then it's an intersection (unless that endpoint is at origin or criminal? But origin is Hannibal's location, wall presumably not there. Criminal at (Xc,Yc); wall could be at criminal? Possibly if criminal is standing at wall? But we can still consider intersection if it shares any point with the wall segment, including endpoints, then it's blocked. However, check if origin or criminal being exactly on wall: Should we treat as intersection? If Hannibal is at (0,0) and wall is there? But constraints X,Y >=1 so wall endpoints and criminal coordinates are >=1, but origin is (0,0) so not coinciding. Criminal could be on the wall? Possibly if criminal is at one of the wall points? The problem statement: "there is a wall between the point (X1, Y1) and (X2, Y2)". So the wall is a segment connecting those points. If criminal is exactly at one of these points, then the criminal is on the wall? Possibly the criminal is not on the wall; but input might allow it. We need to decide. Usually if the criminal is on the wall, then the bullet would hit the wall? Actually if the criminal is exactly on the wall, then the line of sight passes through the wall endpoint; but maybe the bullet hits the criminal exactly at the wall. Could be considered that the wall is in between Hannibal and criminal, meaning the wall blocks if the bullet would have to pass through it before reaching the criminal. If the criminal is on the wall, then there's no "between"? The bullet would hit the criminal at the wall point; it's not blocked because the wall is at that point? Typically if the wall is exactly at the criminal's location, then the criminal is on the wall, so maybe you can shoot him through the wall? The problem likely expects: if the segment from origin to criminal intersects the wall segment (including endpoints) then it's blocked (NO), except maybe if the intersection is exactly at the criminal (or origin) but origin is safe. We need to analyze from sample: In second test, criminal is (1,1) and wall endpoints are (2,2) and (3,3); no intersection, so YES. If criminal were (2,2) and wall from (2,2)-(3,3), then the segment from origin to (2,2) would end at the wall endpoint. Does that count as intersection? The wall is between the two points, but the criminal is at the start of the wall. The bullet would hit the criminal at exactly the wall point. Does the wall block the bullet before reaching the criminal? Possibly not, because the wall is at that point, but the bullet arrives at that point which is the criminal. However, if the criminal is on the wall, one could argue the wall is between Hannibal and criminal if the wall segment is in between. But if the criminal is exactly at the start of the wall, then the line of sight would intersect the wall only at the endpoint which is also the criminal. In typical line-of-sight problems, if the target is exactly on the obstacle, it's considered not blocked because the obstacle does not lie strictly between. But we need to see if problem gives any such scenario. Not in sample. Let's think: The problem is from some contest maybe. Usually they consider that if the segment from shooter to target intersects the wall (including at endpoints), then it's blocked, because the wall occupies that point. However, if the target is on the wall, you might still shoot him, but the bullet would hit the wall at that point as well. But logically, if the wall is a physical barrier, the bullet would need to pass through the wall to hit the criminal if the criminal is behind it. But if the criminal is on the wall, the bullet would hit the wall and the criminal at the same point? It's ambiguous.
Maybe they consider the wall as a line segment that blocks the line of sight if the line of sight crosses it at any point except possibly at the endpoints? Wait, typical problems like "can you see a point from the origin given a wall segment?" treat that if the line segment connecting them intersects the wall segment (including interior or endpoints), then it's blocked, because the wall is an obstacle. However, if the target lies exactly on the wall, then the line of sight ends at the wall, so it's blocked? Actually if the target is on the wall, you can't see it because the wall is in the way? But you can see something that's on the surface? In computer graphics, if a point lies exactly on an obstacle, it's considered visible? It's often a boundary case. In many geometry problems, they consider that if the line of sight touches the wall at only the endpoint, and that endpoint is the target, then it might be considered not blocked. But let's see typical problem: "There is a wall represented by a line segment between two points. Determine if a bullet from shooter to target will hit the wall." Usually if the segment intersects the wall (including at endpoints) then the bullet hits the wall first, thus not reaching the target. But if the target is exactly at the wall, the bullet would hit the wall (and the target) simultaneously; but if the bullet hits the wall, it might stop, so it wouldn't hit the target? Actually if the bullet hits the wall, it may stop, so target not hit. So it's blocked. So answer would be NO. Similarly if the shooter is at the wall, but shooter is at origin and wall points are >=1, so not.
Thus it's safe to treat any intersection (including endpoints) as blocking. Unless they intend "wall between" meaning the wall lies strictly between the two points, i.e., the segment from origin to criminal crosses the interior of the wall segment (not just touching endpoints). But sample: first case, wall endpoints (1,1) and (2,2) lie on line, and criminal at (3,3). The segment from origin to (3,3) passes through the wall interior? Actually it passes through the entire wall including endpoints. If we considered only interior crossing, then it would still be blocked because the line passes through interior points of wall (except maybe if the wall is just a point? but it's a segment). So still blocked. So no distinction.
Second sample: No intersection, YES.
So solution: For each test case, read X1,Y1,X2,Y2,Xc,Yc. Compute whether segment A(0,0) to B(Xc,Yc) intersects segment C(X1,Y1) to D(X2,Y2). Output YES if no intersection, else NO.
We need to implement efficiently for up to T=100, coordinates up to 1e6. Use integer arithmetic, careful about overflow? Cross product might require up to 1e12? 1e6 * 1e6 = 1e12, fits within 64-bit signed (max ~9e18). So use long long.
Standard orientation test and segment intersection detection:
Two segments (p1,q1) and (p2,q2) intersect if the following conditions are satisfied:
-
The orientations of (p1,q1,p2) and (p1,q1,q2) are different (one clockwise, other counterclockwise) and orientations of (p2,q2,p1) and (p2,q2,q1) are different. (General case for non-collinear segments)
-
For collinear segments, they intersect if one endpoint of one segment lies on the other segment. That is, for collinear case, check overlap or point inclusion.
We can implement a function orient(p,q,r) = cross product (q-p) x (r-p). Returns >0, <0, or 0.
Then function onSegment(p,q,r) checks if point q lies on segment pr assuming collinear. That is min(p.x,r.x) <= q.x <= max(p.x,r.x) and similar for y.
Segments intersect if:
orient(A,B,C)*orient(A,B,D) < 0 and orient(C,D,A)*orient(C,D,B) < 0
OR (if any orientation is zero) check collinear cases: if orient(A,B,C)==0 and onSegment(A,C,B)? Actually we need to check if any of the endpoints lies on the other segment. So we can check:
- If orient(A,B,C)==0 and onSegment(A,C,B) then C lies on AB.
- If orient(A,B,D)==0 and onSegment(A,D,B) then D lies on AB.
- If orient(C,D,A)==0 and onSegment(C,A,D) then A lies on CD.
- If orient(C,D,B)==0 and onSegment(C,B,D) then B lies on CD.
But we must be careful: If the segments are collinear and overlapping, then any of the above conditions will be true (like both C and D on AB, or A and B on CD). But we only need to know if they intersect (share at least one point). So if any of these four conditions hold, they intersect. However, be careful: If both segments are collinear but disjoint, none of the onSegment conditions will hold for endpoints of one on the other? Actually if they are collinear but separate, then C and D are not on AB, and A and B are not on CD, so no intersection. So we can handle collinear case with these checks.
But there is also degenerate case where one segment is a point? The wall and the line-of-sight are both segments. Could wall be a point? Possibly if X1,Y1 == X2,Y2? The problem says "between the point (X1,Y1) and (X2,Y2)", typically that defines a segment, could be a point if they are same. But constraints? They didn't specify they are distinct. So we should handle that. Similarly criminal point may be (0,0)? Actually criminal coordinates are >=1 per constraints? It says "1 ≤ X, Y ≤ 1000000". That likely refers to all X1,Y1,X2,Y2,Xc,Yc? It says "1 ≤ X, Y ≤ 1000000". I think all coordinates (including wall endpoints and criminal) are between 1 and 1,000,000. So origin is (0,0) only. So line-of-sight segment starts at (0,0) which is not in that range. So we are safe.
Implementation details:
Define struct Point { ll x, y; }.
orient(p,q,r) = (q.x-p.x)(r.y-p.y) - (q.y-p.y)(r.x-p.x).
onSegment(p, q, r) returns true if q lies on segment pr (assuming collinear). That is min(p.x,r.x) <= q.x <= max(p.x,r.x) and min(p.y,r.y) <= q.y <= max(p.y,r.y). Note inclusive.
Then segmentsIntersect(A,B,C,D):
o1 = orient(A,B,C);
o2 = orient(A,B,D);
o3 = orient(C,D,A);
o4 = orient(C,D,B);
if (o1o2 < 0 && o3o4 < 0) return true;
if (o1 == 0 && onSegment(A,C,B)) return true;
if (o2 == 0 && onSegment(A,D,B)) return true;
if (o3 == 0 && onSegment(C,A,D)) return true;
if (o4 == 0 && onSegment(C,B,D)) return true;
return false;
But careful: In onSegment(A,C,B) we are checking if point C lies on segment AB. That's correct: we need to check if C is between A and B. But we assume C collinear with A and B, which we have o1==0. Similarly for other checks.
Now, for the problem, we want to output YES if can shoot (i.e., no intersection). So if segmentsIntersect returns false, output YES; else NO.
Double-check sample:
Test1: A=(0,0), B=(3,3), C=(1,1), D=(2,2). o1 = orient(A,B,C)=0 (C lies on line). onSegment(A,C,B) => true (1,1 between). So return true -> NO. Good.
Test2: A=(0,0), B=(1,1), C=(2,2), D=(3,3). o1=orient(A,B,C) maybe? Compute: (1,1)-(0,0) = (1,1). C=(2,2) => cross product (12 - 12)=0. So o1=0. Check onSegment(A,C,B): C=(2,2) lies on AB? Segment AB from (0,0) to (1,1). Does (2,2) lie between? No, because x=2 > max(0,1)=1. So false. o2: orient(A,B,D) similarly 0, but onSegment(A,D,B) false because D=(3,3) beyond. o3: orient(C,D,A) = orient((2,2),(3,3),(0,0)) =? Vector (1,1) from C to D; A-C = (-2,-2). cross= 1*(-2)-1*(-2)= -2+2=0. So o3=0. onSegment(C,A,D): A=(0,0) on CD? segment CD from (2,2) to (3,3). (0,0) not between. false. o4: orient(C,D,B)=0? B=(1,1) not between. So all false, so no intersection. Thus YES.
So works.
Now consider other edge cases: The wall might be such that line of sight just touches at an endpoint, not between origin and criminal? Actually if the wall endpoint lies exactly on the segment from origin to criminal, but the endpoint is exactly at the origin? Not possible. If the endpoint is exactly at the criminal? As discussed, likely we treat as intersection -> NO. But if they intend that as not blocking, they would have test cases. Without further info, I'll treat any intersection as blocking. Given typical problems, that's fine.
One more nuance: The segment from origin to criminal is a ray? Actually it's a segment because bullet travels from origin to criminal. If the wall is behind the criminal, i.e., the line extended beyond criminal would intersect the wall, but the segment doesn't reach it, then it's fine. So we only consider segment.
Thus algorithm: For each test case, read 6 integers, then check intersection between segment A(0,0) and B(Xc,Yc) and wall segment C(X1,Y1) to D(X2,Y2). Print "YES" if not intersect, else "NO".
Time O(T). Implementation details: use long long (int64). Input up to 1e6, cross product up to (1e6)*(1e6) = 1e12, but also possible negative, but within 64-bit.
We should also watch out for orientation multiplication overflow? o1*o2 could overflow if product > 2^63-1. o1 and o2 are cross products each up to maybe 1e12? Their product could be 1e24, which exceeds 64-bit (~9e18). So we should not multiply to check sign <0 because overflow could happen. Safer approach: Check (o1>0 && o2<0) || (o1<0 && o2>0) for different signs. Similarly for o3,o4. So implement separate conditions to avoid overflow. Also because values are up to 1e12, product can be as large as 1e24 > 9e18, so definitely overflow. So we avoid multiplication.
Thus use:
if( (o1 > 0 && o2 < 0) || (o1 < 0 && o2 > 0) ) and same for o3,o4.
Now consider collinear case: If all orientations are zero (both segments collinear). Then we need to check overlap. But our current approach of checking each endpoint on other segment will capture any intersection if they overlap or one endpoint lies on the other segment. However, in collinear case where the two segments are collinear but not overlapping, none of the onSegment checks will be true (since each endpoint is not between the other segment). So we return false.
But one subtle case: If the segments are collinear and one of them is a point (i.e., both endpoints same). That point may lie on the other segment. Our onSegment checks will capture if that point is on the other segment: For example, wall is a point (X1,Y1) = (X2,Y2). Then we have C==D. Then we check if C lies on AB: o1==0 and onSegment(A,C,B). That's true if point C lies on segment AB. So intersection true. Conversely, if AB is a point (i.e., Xc=Yc=0? But criminal is at (Xc,Yc) and Xc,Yc>=1, so AB is not a point; origin is distinct). So fine.
Now about orientation function: Since points can be up to 1e6 and origin is 0, the differences can be up to 1e6. Cross product: (B.x - A.x)(C.y - A.y) - (B.y - A.y)(C.x - A.x). For A=(0,0), B=(Xc,Yc), C=(X1,Y1): cross = XcY1 - YcX1. That's within 1e12, safe. For other combos, similar.
Thus we can implement.
Potential pitfalls: Overlap when both segments share a common endpoint. That is captured by onSegment: e.g., if wall endpoint C equals B (criminal). Then o1=0 and onSegment(A,C,B): since C equals B, it's on the segment (endpoint is inclusive). So returns true, thus blocked. So answer would be NO. If the problem expects YES in that case, then we need to treat intersection at criminal as not blocking. But they didn't specify. Given typical "wall between", I'd think if the criminal is on the wall, then the wall is not between; it's at the criminal. But phrase "wall between the point (X1, Y1) and (X2, Y2)" suggests wall is segment; "Hannibal has to shoot a criminal" and "there is a wall between the point ..." implies the wall is an obstacle. If criminal is exactly on the wall, is he behind it? He is on it, so maybe you can shoot him because the bullet hits him and the wall at same time? But wall might block the bullet before it reaches him if the wall is thick? The problem doesn't specify thickness. Typically in such geometry problems, a wall is considered an infinite line? No, it's a segment. If the line of sight touches the wall at a point, it's considered blocked. However, some problems differentiate "strictly between" meaning the intersection point is strictly interior to both segments, not at endpoints. But given sample uses overlapping endpoints and interior, no clue.
Let's search memory: I recall a problem named "Hannibal and the wall" maybe from CodeChef or something. I think I've seen a problem: "Hannibal is on a mission. He has to shoot a criminal." It might be from some contest. I can try to infer from constraints: They gave sample where wall lies exactly on the line and criminal beyond: blocked. The opposite: criminal before wall: not blocked. That suggests they consider the wall as an obstacle that blocks if the line segment from origin to criminal crosses the wall segment. If the criminal lies exactly at the wall endpoint, then the segment ends at the wall. Does it cross? It touches the wall at its endpoint. In many computational geometry problems about line-of-sight, if the target is exactly at the obstacle's endpoint, sometimes it's considered visible because the line-of-sight grazes the obstacle? Actually if the target is at the obstacle, you might not be able to see it because the obstacle occupies that point. But think physically: If there is a wall from A to B, and a person standing exactly at point A on the wall, can someone from origin see him? The person is on the wall, so part of the wall is at that point. The line of sight goes to that point. But does the wall block? If the wall is an opaque object, the point on its edge might be visible if the wall does not extend beyond? At the exact endpoint, the wall ends, so maybe you can see around it? Actually if the wall is a line segment, the endpoints are its ends. So at the endpoint, there is no wall beyond that point. A person standing exactly at the endpoint might be visible because the line of sight reaches that point without passing through the interior of the wall? However, the wall occupies the line segment, but the endpoint is part of the wall. So the point is on the wall. So if the person is standing on the wall, the bullet would hit the wall at that point. So it's blocked. But physically, the wall might be a barrier, and if the person is at the very edge, you might still be able to shoot them because the bullet would travel to that edge without penetrating the wall? Actually if the wall is a physical object, it occupies the region of the segment (including endpoints). The bullet would need to go through the wall if it passes through the interior. But if the target is exactly at the edge, the bullet would hit the target at the same point as the wall's edge. But does the bullet need to go through the wall before reaching that point? The line from origin to that point, if it touches the wall only at that endpoint, then it does not intersect the wall at any other point. So the bullet would not pass through the wall; it would just reach the edge. So it might be possible to shoot. So it's ambiguous.
In many visibility problems, obstacles are considered as closed sets (including boundary). So if the target is on the boundary, it's considered not visible because the line of sight is blocked by the obstacle (the target itself is on the obstacle, but that might be considered occluded). In computer graphics, if an object is exactly at the same location as the viewer's pixel, it's visible. But if a wall is exactly at the target point, then the target is on the wall and might be hidden. Usually in games, if you are on a wall, you can be seen.
But let's see typical competitive programming tasks: For example, a problem "FENCE" or "Wall" often treat intersection as including endpoints. But I'm not sure.
Maybe we can look up known problem: "Hannibal is on a mission" sounds like from CodeChef maybe? I recall a problem "Shooting" or something. Let's search memory: There is a CodeChef problem "SHOOTING" but not sure. Another possibility: This might be from HackerEarth or something. The sample input:
2
1 1 2 2 3 3
2 2 3 3 1 1
They output NO and YES respectively. That's consistent with intersection test including endpoints? In first case, intersection (including endpoint at (1,1) and (2,2) which are interior of line segment from origin to (3,3)? Actually (1,1) is between origin and criminal, so it's an interior point of the line-of-sight segment. So blocked. In second case, the wall segment starts at (2,2) and ends at (3,3), while criminal is at (1,1). The line-of-sight segment ends at (1,1), so it does not include (2,2). So no intersection. So both consistent.
What about a case where criminal is exactly at (2,2) and wall from (2,2)-(3,3)? According to our intersection test, segment from origin to (2,2) would intersect the wall at (2,2) which is an endpoint of wall and endpoint of the line-of-sight. Would that be considered intersection? Our algorithm would say yes (NO). Would the problem expect YES? Not sure. Let's think: If criminal is at the start of the wall, is the wall "between" Hannibal and criminal? The wall is at the same point as criminal, not between. The phrase "there is a wall between the point (X1,Y1) and (X2,Y2)" means the wall is the segment connecting those points. If the criminal is at (X1,Y1) exactly, then the wall extends from criminal to (X2,Y2). So the wall is not between the shooter and criminal because the criminal is at the wall's endpoint. The bullet goes directly to the criminal without passing through the wall. So I'd lean that it should be YES. But we need to confirm via problem statement perhaps they consider that the wall blocks if the line from (0,0) to (Xc,Yc) passes through any point of the wall segment, except possibly the endpoint if that endpoint is the criminal? But then they'd have to define "between" as strictly between. However, the sample doesn't test this. To be safe, we might need to interpret problem as "wall is an obstacle; if the bullet would hit the wall before reaching the criminal, then it's blocked." The bullet travels from (0,0) to (Xc,Yc). If it first hits the wall at some point before reaching (Xc,Yc), then it's blocked. But if the bullet reaches (Xc,Yc) exactly at the same time it reaches the wall (i.e., (Xc,Yc) lies on wall), then the bullet hits criminal and wall simultaneously. Does it count as hitting criminal? Possibly yes, because the bullet would still hit the criminal, even if it also hits the wall. But if the wall is solid, the bullet might be stopped at the wall before reaching the criminal if the wall is in front. But if criminal is on the wall, the bullet would hit the wall at the point where criminal stands. Could still kill the criminal. So I think the intended answer might be YES if the criminal is on the wall. But we need to see if there is any mention: "Hannibal can shoot criminal if the line from (0,0) to (Xc,Yc) does not intersect the wall." That is the typical phrasing. Many problems say "does not intersect" which includes boundary. However, if they meant "does not intersect the interior", they'd say "strictly between". Usually they'd say "if the segment from Hannibal to criminal does not intersect the wall, output YES". So if the criminal is exactly on the wall, the segment does intersect the wall (at the endpoint), so it would be considered intersect -> NO. So ambiguous.
Maybe we can test with a custom case: Suppose wall from (2,2) to (3,3), criminal at (2,2). The line from (0,0) to (2,2) is the same ray. Would they expect YES? I'd try to search memory: I recall a problem "Can Hannibal shoot?" from some platform? Perhaps it's from CodeChef's practice: "Hannibal and the Wall"? I'm not sure. Alternatively, maybe the wall is considered as a line segment that blocks if the line from (0,0) to (Xc,Yc) passes through any point of the wall except possibly the endpoints? Let's think: In the sample, the wall endpoints (1,1) and (2,2) both lie on the line. They intersect, and answer is NO. If we considered endpoints not part of wall, then the segment from (0,0) to (3,3) would intersect the wall interior? Actually the wall interior is all points strictly between (1,1) and (2,2) excluding endpoints. The line from (0,0) to (3,3) passes through the interior too. So it would still be blocked. So sample doesn't differentiate.
Perhaps the problem statement originally said "there is a wall between the points (X1,Y1) and (X2,Y2)". That's all. So we must assume the wall includes its endpoints.
Given that many simple geometry problems treat segments as closed, I'll adopt intersection including endpoints. But I'll also think about corner cases like criminal exactly at one wall endpoint. I might try to see if there is any known solution online? Not possible here.
Alternatively, maybe the problem expects a simpler solution: Since all coordinates are integers, we can use the concept of cross products to check if the criminal, wall, and origin are collinear and then check ordering. But we need general intersection, not just collinear.
Wait, could there be a simpler interpretation? The wall is a "wall" meaning it's a line segment that blocks if the line from origin to criminal crosses it. But perhaps they only consider walls that are axis-aligned? No, coordinates arbitrary.
Maybe the input constraints are such that the wall is either horizontal or vertical? Not stated.
Given typical problems, implementing segment intersection as above is correct.
One more nuance: The segment from (0,0) to (Xc,Yc) is a ray? Actually "shoot" means bullet travels in a straight line. So yes.
Now about output: "YES" if can shoot, else "NO".
Implementation steps:
- Read T.
- Loop T times:
- Read X1, Y1, X2, Y2, Xc, Yc.
- Define points:
A = (0,0)
B = (Xc,Yc)
C = (X1,Y1)
D = (X2,Y2)
- Compute intersection.
- Print "YES" if not intersect, else "NO".
Edge Cases to test:
-
Non-collinear intersection:
E.g., A=(0,0), B=(10,0), C=(5,-1), D=(5,1). The vertical wall at x=5 from y=-1 to y=1. The line from origin to (10,0) passes through (5,0) which is interior of wall. So should be NO. Our algorithm: orientations: o1 = orient(A,B,C) = (10-0)( -1-0) - (0-0)(5-0) = 10*(-1)= -10; o2 = orient(A,B,D) = 101 - 05 = 10; o1 and o2 have opposite signs; o3 = orient(C,D,A) = (1-(-1))(0-5) - (5-5)(0-(-1))? Actually compute: vector CD = (0,2), CA = ( -5,1)?? Wait: C=(5,-1), D=(5,1), so CD = (0,2). A-C = (-5,1). Cross = 01 - 2(-5) = 10; o4 = orient(C,D,B): B-C = (5,1). Cross = 01 - 25 = -10. So opposite signs. So intersection detected -> NO. Good.
-
Non-collinear but just touching at endpoint: e.g., A=(0,0), B=(5,5), C=(5,5), D=(6,6). Wall is from (5,5) to (6,6). Criminal at (5,5)? Actually B is (5,5). So A-B segment ends at B, which is also C. Then o1=orient(A,B,C)=0 and onSegment(A,C,B): C equals B, so onSegment true. So intersection -> NO. But if they want YES, they'd have to treat differently. Without further info, we keep as is.
-
Wall completely behind criminal: A=(0,0), B=(2,2), C=(3,3),(4,4). Then no intersection -> YES.
-
Wall crossing but not collinear: Already tested.
-
Wall such that segment passes through endpoint but not interior: e.g., A=(0,0), B=(4,0), C=(2,0),(2,2). This is a vertical wall starting at (2,0) and going up. The line of sight goes along x-axis from 0 to 4. It passes through (2,0), which is the endpoint of the wall. Does that block? The bullet would hit exactly at the base of the wall. Typically, if the wall is a physical object, the bullet would hit the wall at that point and not reach beyond. Since the bullet's target is at (4,0), the bullet would be blocked at (2,0). So it's blocked. So answer should be NO. Our algorithm: o1=0 for C? C=(2,0) collinear? A=(0,0), B=(4,0), C=(2,0) lies on line. onSegment(A,C,B) true, so intersection -> NO. Good.
If criminal is at (2,0) (the endpoint), then the bullet's target is that point. The bullet would hit the criminal and the wall simultaneously. In a real scenario, if the wall is at that point, the bullet might hit the wall and criminal, but the wall may block the bullet before it reaches the criminal? Actually if the wall is a point object? It's a segment, so at (2,0) the wall exists. The bullet would hit the wall at the same point as the criminal. The bullet might still hit the criminal, but the wall could be in front if the wall extends outward from that point? Actually the wall from (2,0) to (2,2) means there is a vertical wall standing on the line from x=2, y in [0,2]. So at y=0, the wall touches the ground. The criminal standing at (2,0) is at the base of the wall. The bullet traveling along ground (y=0) would hit the wall at its base. It could hit the criminal if the criminal is right there. But the wall might be an obstacle that prevents the bullet from reaching the criminal if the criminal is behind it? But here the criminal is exactly at the wall. The bullet would impact the wall at the same spot the criminal is. Could the bullet penetrate? Not specified. In many simple models, the wall blocks the bullet, so it wouldn't reach the criminal if the bullet is stopped by the wall. So it's blocked. So answer NO. So consistent with our interpretation.
Thus treating any intersection as block seems reasonable.
So solution: implement segment intersection.
Now about integer overflow: Already addressed.
Potential pitfalls: The function onSegment must handle inclusive boundaries. Use <=.
Now consider performance: T up to 100, trivial.
Now let's write the code.
Implementation in C++:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Point {
ll x, y;
};
ll orient(Point p, Point q, Point r) {
return (q.x - p.x)*(r.y - p.y) - (q.y - p.y)*(r.x - p.x);
}
bool onSegment(Point p, Point q, Point r) {
// q lies on segment pr, assuming collinear
return q.x <= max(p.x, r.x) && q.x >= min(p.x, r.x) &&
q.y <= max(p.y, r.y) && q.y >= min(p.y, r.y);
}
bool segmentsIntersect(Point A, Point B, Point C, Point D) {
ll o1 = orient(A, B, C);
ll o2 = orient(A, B, D);
ll o3 = orient(C, D, A);
ll o4 = orient(C, D, B);
// General case
if ((o1 > 0 && o2 < 0) || (o1 < 0 && o2 > 0)) {
if ((o3 > 0 && o4 < 0) || (o3 < 0 && o4 > 0))
return true;
}
// Special cases: collinear
if (o1 == 0 && onSegment(A, C, B)) return true;
if (o2 == 0 && onSegment(A, D, B)) return true;
if (o3 == 0 && onSegment(C, A, D)) return true;
if (o4 == 0 && onSegment(C, B, D)) return true;
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while (T--) {
ll X1, Y1, X2, Y2, Xc, Yc;
cin >> X1 >> Y1 >> X2 >> Y2 >> Xc >> Yc;
Point A = {0, 0};
Point B = {Xc, Yc};
Point C = {X1, Y1};
Point D = {X2, Y2};
bool intersect = segmentsIntersect(A, B, C, D);
cout << (intersect ? "NO" : "YES") << "\n";
}
return 0;
}
Let's test with sample:
Input:
2
1 1 2 2 3 3
2 2 3 3 1 1
First: intersect true -> NO. Second: intersect false -> YES. Matches.
Edge tests:
Case: 1 0 2 0 3 0 (wall horizontal from (1,0) to (2,0), criminal at (3,0)). Origin (0,0) to (3,0) line along x-axis. Wall lies on it from 1 to 2. Intersection -> NO.
Case: 1 0 2 0 1 0? Actually criminal at (1,0) which is wall start. Intersection -> NO.
Case: 1 0 2 0 0 0? Criminal at (0,0) not allowed per constraints (Xc>=1) but if allowed, then segment length zero? Not needed.
Case: Wall vertical: 0 1 0 2 0 3? Actually (0,1)-(0,2) wall, criminal (0,3). Origin (0,0) to (0,3) along y-axis. Intersection -> NO. Good.
Case: Wall not intersecting: 1 2 3 4 5 6 maybe? That line from (0,0) to (5,6) may or may not intersect wall segment from (1,2) to (3,4). They are collinear? Points (0,0), (1,2), (3,4), (5,6) are not collinear because slope 2 vs 4/3? Actually slope from (0,0) to (1,2) is 2, to (3,4) is 4/3≈1.33, not collinear. So likely not intersect. So YES.
Now we need to confirm orientation sign handling.
Potential bug: In general case, we need both conditions: orientations of AB with C and D have opposite signs AND orientations of CD with A and B have opposite signs. Some implementations check if both products <0, but we check separately. So:
if( (o1>0 && o2<0) || (o1<0 && o2>0) ) {
if( (o3>0 && o4<0) || (o3<0 && o4>0) ) return true;
}
That's correct.
We must also consider the case where one of the orientations is zero, but we want to detect intersection only if the zero lies on the segment? Actually if one orientation is zero but the point is not between the endpoints? That could happen if the point is collinear but outside. Our special cases handle those when orientation zero and onSegment true. So we need to not count them in general case because the first condition would not hold if any orientation zero? Actually if o1==0, then the condition (o1>0 && o2<0) || (o1<0 && o2>0) would be false regardless of o2 (since o1 is not >0 nor <0). So it won't return true. Then we go to special case and check if onSegment. Good.
Now for overlapping collinear segments: Suppose wall from (1,1) to (3,3) and criminal at (2,2)? Actually criminal is (2,2) is inside wall? That would be intersection, but note that criminal is on wall. So bullet segment from origin to (2,2) would intersect wall at (2,2). Our special case: o1=0 and onSegment(A,C,B)? But we need to check both endpoints of wall? Actually wall endpoints C=(1,1) and D=(3,3). For criminal B=(2,2), we need to check if segment AB (origin to criminal) intersects wall CD. Since they are collinear and overlapping? Actually segment AB goes from (0,0) to (2,2). Wall CD goes from (1,1) to (3,3). They overlap from (1,1) to (2,2). So there is intersection. Our function: Compute o1=orient(A,B,C) = 0, and onSegment(A,C,B) ? C=(1,1) is on AB? Yes, because between (0,0) and (2,2). So returns true. Good.
Now if they are collinear but disjoint: e.g., wall from (3,3) to (4,4), criminal at (1,1). Then o1=0 but onSegment(A,C,B)? C=(3,3) is not between (0,0) and (1,1). So false. o2=0, onSegment(A,D,B) false; o3=0, onSegment(C,A,D)? A=(0,0) not between (3,3) and (4,4) false; o4=0, onSegment(C,B,D)? B=(1,1) not between, false. So returns false, correct.
Now consider case where the segments cross at interior but one orientation is zero? That can't happen; crossing at interior implies all orientations non-zero with opposite signs. So fine.
Thus solution is correct.
Now, the problem might have a simpler solution because the shooter is at origin and the criminal and wall are in first quadrant (coordinates positive). But still intersection check is needed.
Now about the constraints: X, Y up to 1e6. So cross product up to 1e12 as said.
Now about reading: we have to read T and then T lines each with six integers. Input sample shows each test case on a single line.
Now output: "YES" or "NO" uppercase.
Thus final solution.
We might need to consider that the wall could be such that it crosses the line from origin to criminal but the intersection point is beyond the criminal? Actually that's impossible because the segment ends at criminal. So no.
Now, I'll produce final answer.
But before finalizing, let's think about alternative interpretations: Could the problem be as simple as checking whether the criminal is on the same side of the wall as Hannibal? Because the wall is a line segment, but if it's considered as a line, then the line from origin to criminal would be blocked if the criminal is behind the wall? But no, because wall is a segment, not infinite. So need intersection.
Maybe they want to check if the line from origin to criminal passes through the wall segment, i.e., if the criminal, origin, and the wall are collinear and the criminal is beyond the wall? But sample test2: wall from (2,2)-(3,3) and criminal (1,1) are collinear but criminal is before wall, answer YES. So if they only considered collinear case, they would still need to check ordering. But non-collinear walls also block if they cross. So must handle general intersection.
Thus geometry solution stands.
Now, about potential overflow in orientation when we compute (q.x-p.x)(r.y-p.y) - ... The product can be up to (1e6)(1e6)=1e12, but we store in long long (signed 64-bit). 1e12 is safe. Could be negative values as well, but magnitude same. So fine.
Now I think we are done.
Let's produce final answer code.
But I'll include comments for clarity.
Also note: The problem might require that if the wall is just a point, treat as a point obstacle. Our code works.
Now test with some random cases:
Case: T=1, input: 0 0 0 0 1 1? But constraints say X,Y>=1, so wall points also >=1. So no zero coordinates for wall. So origin unique.
Edge: large coordinates: 1000000 1 1000000 2 500000 500000? That's fine.
Now I'm satisfied.
One more: When the segments intersect exactly at the origin? Not possible.
Thus final.
However, there is another nuance: The problem says "Hannibal was on the point (0, 0) and the criminal is on the point (Xc, Yc). But there is a wall between the point (X1, Y1) and (X2, Y2)." The phrase "between the point (X1,Y1) and (X2,Y2)" might indicate the wall is the line segment joining them. So correct.
Now produce final answer. ```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Point {
ll x, y;
};
// Cross product (q-p) x (r-p)
ll orient(const Point& p, const Point& q, const Point& r) {
return (q.x - p.x) * (r.y - p.y) - (q.y - p.y) * (r.x - p.x);
}
// Returns true if point q lies on segment pr (collinearity assumed)
bool onSegment(const Point& p, const Point& q, const Point& r) {
return q.x <= max(p.x, r.x) && q.x >= min(p.x, r.x) &&
q.y <= max(p.y, r.y) && q.y >= min(p.y, r.y);
}
// Checks whether segment AB and CD intersect (including endpoints)
bool segmentsIntersect(const Point& A, const Point& B,
const Point& C, const Point& D) {
ll o1 = orient(A, B, C);
ll o2 = orient(A, B, D);
ll o3 = orient(C, D, A);
ll o4 = orient(C, D, B);
// General case: straddling both segments
if (((o1 > 0 && o2 < 0) || (o1 < 0 && o2 > 0)) &&
((o3 > 0 && o4 < 0) || (o3 < 0 && o4 > 0))) {
return true;
}
// Special cases: collinear and one endpoint lies on the other segment
if (o1 == 0 && onSegment(A, C, B)) return true;
if (o2 == 0 && onSegment(A, D, B)) return true;
if (o3 == 0 && onSegment(C, A, D)) return true;
if (o4 == 0 && onSegment(C, B, D)) return true;
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while (T--) {
ll X1, Y1, X2, Y2, Xc, Yc;
cin >> X1 >> Y1 >> X2 >> Y2 >> Xc >> Yc;
Point A = {0, 0}; // Hannibal
Point B = {Xc, Yc}; // Criminal
Point C = {X1, Y1}; // Wall endpoints
Point D = {X2, Y2};
bool blocked = segmentsIntersect(A, B, C, D);
cout << (blocked ? "NO" : "YES") << "\n";
}
return 0;
}