Logo
(追記) (追記ここまで)

30933번 - Color Inversion on a Huge Chessboard 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 (추가 시간 없음) 1024 MB131898670.492%

문제

You are given a set of square cells arranged in a chessboard-like pattern with $n$ horizontal rows and $n$ vertical columns. Rows are numbered 1ドル$ through $n$ from top to bottom, and columns are also numbered 1ドル$ through $n$ from left to right.

Initially, the cells are colored as in a chessboard, that is, the cell in the row $i$ and the column $j$ is colored black if $i + j$ is odd and is colored white if it is even.

Color-inversion operations, each of which is one of the following two, are made one after another.

Invert colors of a row: Given a row number, invert colors of all the cells in the specified row. The white cells in the row become black and the black ones become white.

Invert colors of a column: Given a column number, invert colors of all the cells in the specified column. The white cells in the column become black and the black ones become white.

The number of distinct areas after each of the operations should be counted. Here, an area means a group of directly or indirectly connected cells of the same color. Two cells are said to be directly connected when they share an edge.

입력

The input consists of a single test case of the following format.

$n$ $q$

$operation_1$

$\vdots$

$operation_q$

The integer $n$ is the number of rows and columns (1ドル ≤ n ≤ 5 \times 10^5$). The integer $q$ is the number of operations (1ドル ≤ q ≤ 5 \times 10^5$). The following $q$ lines represent operations to be made in this order. Each of them is given in either of the following forms.

  • ROW $i$: the operation “invert colors of a row” applied to the row $i$ (1ドル ≤ i ≤ n$).
  • COLUMN $j$ : the operation “invert colors of a column” applied to the column $j$ (1ドル ≤ j ≤ n$).

출력

Output $q$ lines. The $k$-th line should contain an integer denoting the number of areas after the $k$-th operation is made.

제한

예제 입력 1

3 3
ROW 2
COLUMN 3
ROW 2

예제 출력 1

3
2
6

예제 입력 2

200000 2
ROW 1
ROW 1

예제 출력 2

39999800000
40000000000

힌트

Figure F.1. Illustration of Sample Input 1

출처

ICPC > Regionals > Asia Pacific > Japan > ICPC 2023 Asia Yokohama Regional F번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /