Master of Both V

시간 제한5초메모리 제한2048 MB

요약
세그먼트의 동적 집합을 유지하면서 각 갱신 후 모든 세그먼트가 하나의 볼록 다각형의 변 위에 놓일 수 있는지 판정한다.
난이도

어려움10점 중 9점

유형
기하, 동적 계획법, 그리디, 구현
정답자
아직 제출이 없습니다

문제

Prof. Chen is the master of data structure and computational geometry. Recently, he taught Putata and Budada the definition of convex polygon. A convex polygon is a simple polygon (i.e., no two vertices coincide and no two edges intersect unless two continuous edges intersect at a vertex) with all interior angles strictly less than π\pi.

Putata and Budada solved the convex checker problem, but Prof. Chen asked them to go further, which they have to maintain a multiset of segments SS, supporting the following two types of inquiries:

  • ++ pxpx pypy qxqx qyqy, insert segment with endpoints (px,py),(qx,qy)(px,py), (qx,qy) to the multiset SS.
  • −- ii, erase the segment inserted in the ii-th inquiry. It is guaranteed that the ii-th inquiry is an inserting inquiry and the corresponding segment is currently in the multiset.

After each inquiry, Putata and Budada needs to answer if there exists a convex polygon C\mathcal{C}, where the vertices of the convex polygon are p_0,p_1,p_2,…,p_m−1p\_0,p\_1,p\_2,\dots,p\_{m-1} in counter clockwise order, satisfying that for all segment u∈Su\in S, exists j∈0,1,2,…,m−1j\in\\{0,1,2,\dots,m-1\\} such that u⊆p_jp_(j+1) mod mu\subseteq p\_jp\_{(j+1)\bmod m}. For two segments e,fe, f, we say e⊆fe\subseteq f if and only if for all point z∈ez\in e, satisfying that z∈fz\in f.

Please help Putata and Budada to solve this problem.

입력

Each test contains multiple test cases. The first line contains a single interger tt (1≤t≤5⋅1051 \leq t \leq 5 \cdot 10^5), denoting the number of test cases.

For each test case, the first line contains an integer nn (1≤n≤5⋅1051\leq n\leq 5\cdot 10^5), denoting the number of inquiries.

Each of the folowing nn lines contains one inquiry. The inquiry begins with a character opop (op∈+,−op\in\\{+,-\\}).

If op=+op=+, then four integers px,py,qx,qypx, py, qx, qy (−109≤px,py,qx,qy≤109-10^9\leq px,py,qx,qy\leq 10^9) follows, denoting an inserting inquiry. It is guaranteed that px≠qxpx\neq qx or py≠qypy \neq qy.

Otherwise an integer ii (1≤i≤n1\leq i\leq n) follows, denoting an erasing inquiry. It is guaranteed that the ii-th inquiry is an inserting inquiry and the corresponding segment is currently in the multiset.

It is guaranteed that the sum of nn does not exceed 5⋅1055\cdot 10^5.

출력

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

예제1

  1. 예제 1

    입력
    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
    
    예상 출력
    11000001
    11011
    1101
    1111