Problem2227--QueenS ATTACK

2227: QueenS ATTACK

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MB

Description

给定一个大小为N的国际象棋棋盘(即N行N列的棋盘),然后给出Q个查询,每次查询给出两个整数x和y,分别代表放置的行号和列号。

对于每一次查询,你需要判断:如果将一个皇后放在这个位置上,不会产生两个或更多个皇后之间的互相攻击,则打印YES,并将皇后摆放在该位置上;如果会产生互相攻击,打印NO,然后并不放置该皇后。

(注:皇后的移动规则是:行、列、两条对角线方向均可移动,请见下图所示,当皇后位于d4时,图中所有黑点所示的方格,均为该皇后的攻击范围

You are playing a variation on the chess game on board with N×NN×N squares. Rows and columns are numbered from 11 to NN. You also have QQ queens. Let us remind that the queen is a piece in chess that can move any number of squares horizontally, vertically, or diagonally.

You will be placing the queens on the board. The only condition is that no two queens can attack each other. Before each placement, you have to determine if placing a queen in this particular place is safe from the already placed queens. If the place is not safe, you don't put the queen at that place and just continue checking new positions.

Input

The first line contains two integers NN and QQ (1≤N,Q≤1000001≤N,Q≤100000), the size of the board and the number of queries respectively.

The next QQ lines contain two integers XiXi and YiYi (1≤Xi,Yi≤N1≤Xi,Yi≤N) – the position where we want to place the queen. We will never try to put a queen at the same place that we already tried to put a queen before, so all pairs (Xi,Yi)(Xi,Yi) will be different.

Output

For ii-th query, output YES if placing the ii-th queen was successful (it didn't cause any two queens attacking each other) or NO otherwise.

Sample Input Copy

8 8
4 5
2 6
8 4
7 6
2 1
1 3
8 3
3 2

Sample Output Copy

YES
YES
YES
NO
NO
YES
NO
YES

Source/Category