Under construction

Still being built. Things may change

Polygonal Query

Time limit1sMemory limit512 MB

Summary
Points are added one at a time, and for each query the task is to report whether the clockwise or counterclockwise hull path between two hull vertices passes more hull points.
Level

Hard8 of 10

Topics
Geometry, Tree
Solved
No attempts yet

Problem

Let SS be a set of points on a 2-dimensional plane. Initially, SS is an empty set. Let convexHull(SS) be the subset of SS that contains the vertices of the convex hull of SS, with no three collinear points.

There are QQ queries. Each query is one of the following two types.

  1. add(xx, yy): Adds the point (xx, yy) to SS. No two points share the same xx coordinate or the same yy coordinate.
  2. findHeavy(x1x_1, y1y_1, x2x_2, y2y_2): The points (x1x_1, y1y_1) and (x2x_2, y2y_2) are distinct points of convexHull(SS). This query is only called when convexHull(SS) has at least three points. A robot is at (x1x_1, y1y_1) and wants to go to (x2x_2, y2y_2). The robot can only move along the edges of the convex hull. Let cwcw be the number of points of convexHull(SS) that the robot passes when it moves clockwise, and let ccwccw be the number it passes when it moves counterclockwise. If cw≥ccwcw \ge ccw, output "CW". Otherwise, output "CCW".

Input

The first line contains an integer QQ (1≤Q≤1000001 \le Q \le 100000). The next QQ lines each contain three or five integers.

  • If the ii-th query is add(xx, yy), the ii-th line is 0 xx yy (0≤x,y≤10000000 \le x, y \le 1000000).
  • If the ii-th query is findHeavy(x1x_1, y1y_1, x2x_2, y2y_2), the ii-th line is 1 x1x_1 y1y_1 x2x_2 y2y_2 (0≤x1,y1,x2,y2≤10000000 \le x_1, y_1, x_2, y_2 \le 1000000).

Output

For each findHeavy query, print the answer on its own line.

Examples1

  1. Example 1

    Input
    14
    0 0 2
    0 4 6
    0 5 1
    1 0 2 4 6
    1 4 6 0 2
    0 1 5
    0 6 4
    1 0 2 4 6
    1 0 2 5 1
    0 3 3
    1 0 2 6 4
    0 2 0
    1 0 2 6 4
    1 6 4 0 2
    
    Expected output
    CCW
    CW
    CCW
    CW
    CW
    CW
    CW