GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Saturday, 14 May 2022

Rooks Defenders Codeforces Solution | Codeforces Problem Solution 2022

C. Rooks Defenders
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have a square chessboard of size n×n. Rows are numbered from top to bottom with numbers from 1 to n, and columns — from left to right with numbers from 1 to n. So, each cell is denoted with pair of integers (x,y) (1≤x,y≤n), where x is a row number and y is a column number.

Solution Click Below:-  CLICK HERE

You have to perform q queries of three types:

  • Put a new rook in cell (x,y).
  • Remove a rook from cell (x,y). It's guaranteed that the rook was put in this cell before.
  • Check if each cell of subrectangle (x1,y1)−(x2,y2) of the board is attacked by at least one rook.

Subrectangle is a set of cells (x,y) such that for each cell two conditions are satisfied: x1≤x≤x2 and y1≤y≤y2.


Recall that cell (a,b) is attacked by a rook placed in cell (c,d) if either a=c or b=d. In particular, the cell containing a rook is attacked by this rook.

Input

The first line contains three integers n and q (1≤n≤105, 1≤q≤2⋅105) — the size of the chessboard and the number of queries, respectively.

Each of the following q lines contains description of a query. Description begins with integer t (t∈{1,2,3}) which denotes type of a query:

  • If t=1, two integers x and y follows (1≤x,y≤n) — coordinated of the cell where the new rook should be put in. It's guaranteed that there is no rook in the cell (x,y) at the moment of the given query.
  • If t=2, two integers x and y follows (1≤x,y≤n) — coordinates of the cell to remove a rook from. It's guaranteed that there is a rook in the cell (x,y) at the moment of the given query.
  • If t=3, four integers x1,y1,x2 and y2 follows (1≤x1≤x2≤n, 1≤y1≤y2≤n) — subrectangle to check if each cell of it is attacked by at least one rook.

It's guaranteed that among q queries there is at least one query of the third type.

Output

Print the answer for each query of the third type in a separate line. Print "Yes" (without quotes) if each cell of the subrectangle is attacked by at least one rook.

Otherwise print "No" (without quotes).

Join Now for Solution:- 

No comments:

Post a Comment