cswork / OAOpen practice workspace

DatabricksOA #5

Rectangle Fit in Box (with Rotation)

Estimated EasyJudge-ready

Topics (AI-labelled)In-place ArraysGreedy

Execute two kinds of operations in order: 0 a b stores an a×b rectangle; 1 a b asks whether every previously stored rectangle can individually fit into an a×b query box. Rectangles may be rotated 90 degrees; each rectangle is placed separately, and they do not need to fit into the same box at the same time.

Standard input/output, this site's supplementary ranges, and the examples follow this problem's description.

Input

The first line contains q (1≤q≤30000), followed by q lines each containing kind, a, and b. kind is 0 or 1, and 1≤a,b≤10⁹. These ranges are site supplements that keep the worst-case output length within the judge's limit.

Output

Output one line per query operation: 1 if they fit, otherwise 0. When no rectangles have been stored, the query result is 1.

Example 1

Input:

4
0 1 3
0 4 2
1 3 4
1 3 2

Output:

1
0

Example 2

Input:

4
1 1 1
0 2 5
1 5 2
1 4 2

Output:

1
1
0

Example 3

Input:

4
0 2 2
0 3 1
1 3 2
1 3 3

Output:

1
1

Editorial

Loading solution…