Under construction

Still being built. Things may change

Master of Both V

Time limit5sMemory limit2048 MB

Summary
After each insertion or deletion, report whether some convex polygon exists that has every segment in the multiset lying on one of its edges.
Level

Hard10 of 10

Topics
Geometry, Segment tree, Sorting
Solved
No attempts yet

Problem

Prof. Chen is the master of data structures and computational geometry. Recently, he taught Putata and Budada the definition of a convex polygon. A convex polygon is a simple polygon (that is, no two vertices coincide, and no two edges intersect unless two consecutive edges meet at a vertex) whose interior angles are all strictly less than π\pi.

Putata and Budada solved the convex checker problem. Prof. Chen then asked them to go further: maintain a multiset of segments SS that supports two types of queries.

  • ++ pxpx pypy qxqx qyqy: insert the segment with endpoints (px,py)(px,py) and (qx,qy)(qx,qy) into the multiset SS.
  • −- ii: erase the segment inserted by the ii-th query. It is guaranteed that the ii-th query is an insertion and that its segment is currently in the multiset.

After each query, answer whether there exists a convex polygon C\mathcal{C} with vertices p0,p1,p2,…,pm−1p_0,p_1,p_2,\dots,p_{m-1} in counterclockwise order such that for every segment u∈Su\in S, there is some j∈{0,1,…,m−1}j\in\{0,1,\dots,m-1\} with u⊆pjp(j+1) mod mu\subseteq p_jp_{(j+1)\bmod m}. For two segments e,fe,f, e⊆fe\subseteq f holds if and only if every point z∈ez\in e also lies in ff.

Input

The first line contains a single integer tt (1≤t≤5⋅1051 \le t \le 5 \cdot 10^5), the number of test cases.

Each test case starts with a line containing an integer nn (1≤n≤5⋅1051\le n\le 5\cdot 10^5), the number of queries. Each of the following nn lines contains one query. A query begins with a character opop (op∈{+,−}op\in\{+,-\}).

If op=+op=+, four integers px,py,qx,qypx, py, qx, qy (−109≤px,py,qx,qy≤109-10^9\le px,py,qx,qy\le 10^9) follow. It is guaranteed that px≠qxpx\neq qx or py≠qypy \neq qy.

Otherwise, an integer ii (1≤i≤n1\le i\le n) follows. It is guaranteed that the ii-th query is an insertion and that its segment is currently in the multiset.

The sum of nn over all test cases does not exceed 5⋅1055\cdot 10^5.

Output

For each test case, print a string of '0' and '1' on one line. The ii-th character is '1' if the answer is true after the ii-th query, and '0' otherwise.

Examples1

  1. Example 1

    Input
    4
    8
    + 0 0 1 0
    + 5 5 1 3
    + 2 0 2 1
    + 9 7 6 2
    + 1 2 2 2
    - 4
    + 0 1 0 2
    - 2
    5
    + 0 0 1 1
    + 0 1 1 2
    + 0 2 1 3
    - 2
    + 1 1 10 10
    4
    + 0 0 1 1
    + 0 0 1 0
    + 0 0 0 1
    - 1
    4
    + 0 0 1 1
    + 0 0 1 1
    - 1
    - 2
    
    Expected output
    11000001
    11011
    1101
    1111