Counting Regions
시간 제한2초메모리 제한1024 MB
2N-2번의 행/열 칠하기 연산 각각이 끝난 뒤 단색 연결 영역의 개수를 구하고, 연산 색을 범위로 뒤집는 누적 질의를 처리한다.
문제
You are given an grid. A cell in the -th row and -th column is denoted as . Initially, every cell on the grid is colored white.
We will color each cell using operations. The -th operation is denoted as . An operation of form indicates the following:
- For , we color cells in the -th column. For , we color cells in a -th row.
- For , we color the column/row white. For , we color the column/row black.
It is guaranteed that if you carry out the operation in the order, each of the -th row will be colored exactly once in that order, and each of the -th column will be colored exactly once in that order. Note that no operation colors the first row and the first column. Formally, the following holds:
- For all integers such that and , there is a unique integer such that .
- For all integers such that and , holds.
A region is defined as maximal sections of neighboring cells of the same color, where two cells are considered neighbors if they share an edge. You need to find the number of regions after performing each operation in the given order.
Of course, this problem is too easy, so we prepared queries for you! Each query is denoted as integers . After the query, you should set for all -th operation where holds. Then, with the changed operation sequence, you need to find the number of regions after performing each operation. Note that the queries are cumulative.
입력
The first line contains two space-separated integers and .
The -th line of the next lines contains three space-separated integers , , .
The -th line of next lines contains three space-separated integer , , , describing the -th query.
출력
After each query, output a line with a single integer, which is the number of regions.
제한
- For each operation, and
- For all integers such that and , there is a unique integer such that .
- For all integers such that and , holds.
- ; for each query.
힌트

State of the grid after each operation for example 2