Under construction

Still being built. Things may change

Rooks

Interview

Time limit2sMemory limit1024 MB

Summary
Given two players' rooks on a plane, find each rook that has an opposing rook as its nearest neighbor in the same row or column.
Level

Medium4 of 10

Topics
Sorting, Hash map, Implementation
Solved
No attempts yet

Problem

Prof. Pang plays chess against his rival Prof. Shou. They are the only two players in the game. The chessboard is very large and can be viewed as a 2D plane. Prof. Pang placed n1n_1 rooks and Prof. Shou placed n2n_2 rooks. Each rook is a point with integer coordinates on the chessboard. A rook is attacked by another rook if all of the following hold:

  • They are placed by different players.
  • They have the same x-coordinate or y-coordinate.
  • There is no other rook on the line segment between them.

Help Prof. Pang and Prof. Shou decide which rooks are attacked.

Input

The first line contains two integers n1n_1 and n2n_2 (1≤n1,n2≤2000001 \le n_1, n_2 \le 200000), separated by a single space. They are the number of rooks placed by Prof. Pang and the number of rooks placed by Prof. Shou. The next n1n_1 lines each contain two integers x,yx, y (−109≤x,y≤109-10^9 \le x, y \le 10^9), separated by a single space, giving the location of one rook placed by Prof. Pang. The next n2n_2 lines follow in the same format for the rooks placed by Prof. Shou. All rooks are at distinct locations.

Output

The first line is a string of length n1n_1. The ii-th character is 1 if the ii-th rook placed by Prof. Pang is attacked, and 0 otherwise. The second line is a string of length n2n_2. The ii-th character is 1 if the ii-th rook placed by Prof. Shou is attacked, and 0 otherwise.

Examples1

  1. Example 1

    Input
    3 2
    0 0
    0 1
    1 0
    0 -1
    -1 0
    
    Expected output
    100
    11