CF1679C.Rooks Defenders

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

You have to perform qq queries of three types:

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

Subrectangle is a set of cells (x,y)(x, y) such that for each cell two conditions are satisfied: x1≤x≤x2x_1 \le x \le x_2 and y1≤y≤y2y_1 \le y \le y_2.

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

你有一个 n×nn \times n 的正方形国际象棋棋盘。行从上到下编号为 11 到 nn,列从左到右编号为 11 到 nn。因此,每个格子用一对整数 (x,y)(x, y)(其中 1≤x,y≤n1 \le x, y \le n)表示,其中 xx 为行号,yy 为列号。

你需要执行 qq 个查询,共三种类型:

  • 在格子 (x,y)(x, y) 放置一枚新的车(rook);
  • 从格子 (x,y)(x, y) 移除一枚车;保证该格子此前已放置过车;
  • 检查棋盘的子矩形区域 (x1,y1)−(x2,y2)(x_1, y_1) - (x_2, y_2) 中的每个格子是否至少被一枚车攻击。

子矩形是指满足以下两个条件的所有格子 (x,y)(x, y) 构成的集合:x1≤x≤x2x_1 \le x \le x_2 且 y1≤y≤y2y_1 \le y \le y_2。

回忆:当且仅当 a=ca = c 或 b=db = d 时,位于 (c,d)(c, d) 的车会攻击格子 (a,b)(a, b)。特别地,放置车的格子本身也被该车所攻击。

输入格式

The first line contains two integers nn and qq (1≤n≤1051 \le n \le 10^5, 1≤q≤2⋅1051 \le q \le 2 \cdot 10^5) — the size of the chessboard and the number of queries, respectively.

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

  • If t=1t = 1, two integers xx and yy follows (1≤x,y≤n1 \le x, y \le 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)(x, y) at the moment of the given query.
  • If t=2t = 2, two integers xx and yy follows (1≤x,y≤n1 \le x, y \le n) — coordinates of the cell to remove a rook from. It's guaranteed that there is a rook in the cell (x,y)(x, y) at the moment of the given query.
  • If t=3t = 3, four integers x1,y1,x2x_1, y_1, x_2 and y2y_2 follows (1≤x1≤x2≤n1 \le x_1 \le x_2 \le n, 1≤y1≤y2≤n1 \le y_1 \le y_2 \le n) — subrectangle to check if each cell of it is attacked by at least one rook.

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

第一行包含两个整数 nn 和 qq(1≤n≤1051 \le n \le 10^5,1≤q≤2⋅1051 \le q \le 2 \cdot 10^5),分别表示棋盘的大小和查询的数量。

接下来的 qq 行每行描述一个查询。每行以整数 tt(t∈{1,2,3}t \in \{1, 2, 3\})开头,表示查询的类型:

  • 若 t=1t = 1,则随后是两个整数 xx 和 yy(1≤x,y≤n1 \le x, y \le n),表示新放置车的位置坐标。保证在该查询执行时刻,格子 (x,y)(x, y) 上没有车。
  • 若 t=2t = 2,则随后是两个整数 xx 和 yy(1≤x,y≤n1 \le x, y \le n),表示要移除车的格子坐标。保证在该查询执行时刻,格子 (x,y)(x, y) 上有一辆車。
  • 若 t=3t = 3,则随后是四个整数 x1,y1,x2x_1, y_1, x_2 和 y2y_2(1≤x1≤x2≤n1 \le x_1 \le x_2 \le n,1≤y1≤y2≤n1 \le y_1 \le y_2 \le n),表示待检查的子矩形区域,需判断该子矩形内的每个格子是否均至少被一辆车攻击。

保证在全部 qq 个查询中,至少存在一个类型为 3 的查询。

输出格式

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).

对每个第三种类型的查询,单独输出一行答案。如果子矩形中的每个格子都至少被一个车攻击,则输出 “Yes”(不带引号);
否则输出 “No”(不带引号)。

输入输出样例

  • 输入#1

    8 10
    1 2 4
    3 6 2 7 2
    1 3 2
    3 6 2 7 2
    1 4 3
    3 2 6 4 8
    2 4 3
    3 2 6 4 8
    1 4 8
    3 2 6 4 8

    输出#1

    No
    Yes
    Yes
    No
    Yes

说明/提示

Consider example. After the first two queries the board will look like the following picture (the letter RR denotes cells in which rooks are located, the subrectangle of the query of the third type is highlighted in green):

Chessboard after performing the third and the fourth queries:

Chessboard after performing the fifth and the sixth queries:

Chessboard after performing the seventh and the eighth queries:

Chessboard after performing the last two queries:

考虑一个示例。在执行前两个查询后,棋盘将如下图所示(字母 RR 表示放置车(rook)的格子,第三类查询所指定的子矩形区域以绿色高亮显示):

执行第三和第四次查询后的棋盘:

执行第五和第六次查询后的棋盘:

执行第七和第八次查询后的棋盘:

执行最后两次查询后的棋盘:

输入解题思路,AI测评打分。不知道怎么写?

首页