| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 (추가 시간 없음) | 1024 MB (추가 메모리 없음) | 18 | 8 | 8 | 66.667% |
You are given an $N\times N$ grid. A cell in the $i$-th row and $j$-th column is denoted as $(i,j)$. Initially, every cell on the grid is colored white.
We will color each cell using $2N-2$ operations. The $i$-th operation is denoted as $(d_i,x_i,c_i)$. An operation of form $(d,x,c)$ indicates the following:
It is guaranteed that if you carry out the operation in the order, each of the $2,3,4,\ldots ,N$-th row will be colored exactly once in that order, and each of the $2,3,4,\ldots ,N$-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:
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 $2N-2$ operation in the given order.
Of course, this problem is too easy, so we prepared $Q$ queries for you! Each query is denoted as $3$ integers $(z,l,r)$. After the query, you should set $c_i=1-c_i$ for all $i$-th operation where $l\le x_i\le r,d_i=z$ holds. Then, with the changed operation sequence, you need to find the number of regions after performing each $2N-2$ operation. Note that the queries are cumulative.
The first line contains two space-separated integers $N$ and $Q$.
The $i$-th line of the next $2N-2$ lines contains three space-separated integers $d_i$, $x_i$, $c_i$.
The $i$-th line of next $Q$ lines contains three space-separated integer $z$, $l$, $r$, describing the $i$-th query.
After each query, output a line with a single integer, which is the number of regions.
5 7 1 2 0 0 2 0 1 3 1 1 4 0 1 5 1 0 3 1 0 4 1 0 5 1 1 3 5 0 4 4 0 2 5 1 2 3 1 5 5 1 3 4 0 2 4
3 5 5 5 5 6 4
3 6 0 2 0 1 2 1 0 3 0 1 3 1 0 2 2 0 2 3 0 3 3 1 2 2 1 2 3 1 3 3
3 2 2 2 2 2
State of the grid after each operation for example 2
University > KAIST > KAIST ICPC Mock Competition > 2024 KAIST 14th ICPC Mock Competition C번