AtCoder Beginner Contest 461
E
E-liter
AtCoder
⌀ 1431
原题
←F →

E-literAI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

There is an $N \times N$ grid. Initially, all cells are painted white.

有一个 $N \times N$ 的网格。初始时,所有格子均被涂成白色。AI (CI翻译)

Process $Q$ queries in the given order. Each query is one of the following:

请按给定顺序处理 $Q$ 次查询。每次查询属于以下两种类型之一:AI (CI翻译)

  • Type $1$: An integer $R$ is given. Paint all cells in the $R$-th row from the top of the grid black.
  • Type $2$: An integer $C$ is given. Paint all cells in the $C$-th column from the left of the grid white.
  • 类型 $1$:给定一个整数 $R$。将网格从上往下数第 $R$ 行的所有格子涂成黑色。
  • 类型 $2$:给定一个整数 $C$。将网格从左往右数第 $C$ 列的所有格子涂成白色。
AI (CI翻译)

After processing each query, output the number of black cells in the grid at that point.

每次处理完一个查询后,输出此时网格中黑色格子的数量。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \leq N, Q \leq 3 \times 10^5$
  • For type $1$ queries, $1 \leq R \leq N$.
  • For type $2$ queries, $1 \leq C \leq N$.
  • All input values are integers.
  • $1 \leq N, Q \leq 3 \times 10^5$
  • 对于类型 $1$ 的查询,$1 \leq R \leq N$。
  • 对于类型 $2$ 的查询,$1 \leq C \leq N$。
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入从标准输入按以下格式给出:AI (CI翻译)

N Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q

N Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
AI (CI翻译)

Here, $\text{query}_i$ is the $i$-th query, given in one of the following formats.

其中,$\text{query}_i$ 表示第 $i$ 次查询,格式为以下两种之一。AI (CI翻译)

Type $1$:

类型 $1$:AI (CI翻译)

1 R

1 R
AI (CI翻译)

Type $2$:

类型 $2$:AI (CI翻译)

2 C

2 C
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output $Q$ lines. The $i$-th line should contain the number of black cells in the grid at the time the $i$-th query has been processed.

输出 $Q$ 行。第 $i$ 行应包含处理完第 $i$ 次查询时网格中黑色格子的数量。AI (CI翻译)

样例

Input #1
3 4
1 1
1 3
2 2
1 1
Output #1
3
6
4
5
The changes in the grid are shown using characters. `.` represents a white cell, and `#` represents a black cell.
Input #2
300000 1
2 300000
Output #2
0
Beware of overflow in larger cases.
题目信息
题号
abc461_e
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。