#P9917. 「RiOI-03」网格

    ID: 10378 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>树状数组洛谷原创O2优化洛谷月赛分类讨论

「RiOI-03」网格

Background

During a training lecture in 2022, a problem appeared in the slides whose input variables were strictly ordered by the initials of MLE’s real name. MLE wanted to use the initials of vectorwyx as the input variables in their own problem, and thus this problem was created.

Unfortunately, vectorwyx has now retired. Everyone has their own dreams, and each shines in their own way.

Problem Description

Please read the Constraints of this problem carefully.

You are given an n×nn \times n square grid with nn rows and nn columns. Initially, all cells are red. There are nn queries. Each query recolors an entire row or an entire column to red or white. After each query, output the perimeter of all red cells. The queries are not independent.

Input Format

The first line contains a positive integer nn.

Each of the next nn lines contains three positive integers w,y,xw, y, x. ww indicates the color: w=1w=1 means recolor to red, and w=0w=0 means recolor to white. yy indicates row or column: y=1y=1 means recolor the entire xx-th row, and y=0y=0 means recolor the entire xx-th column.

Output Format

There are nn lines. Each line contains one integer, representing the perimeter of the red region after each modification.

5
0 0 3
0 1 2
0 1 4
1 0 2
1 1 4
28
32
36
36
32

Hint

Sample Explanation

Sample image explanation.

Constraints

For 100%100\% of the data, 3n1063\leq n \leq 10^6 , 1<x<n1<x<n.

$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|c|c|} \hline \textbf{\textsf{\#}} & \bm{{n\le}} & \textbf{\textsf{Special Properties}} & \textbf{\textsf{\#}} & \bm{{n\le}} & \textbf{\textsf{Special Properties}}\cr\hline 1 & 5 & - & 11 & 10^5 & - \cr\hline 2 & 100 & - & 12 & 10^5 & - \cr\hline 3 & 100 & - & 13 & 10^5 & - \cr\hline 4 & 2000 & \textbf{A} & 14 & 10^5 & - \cr\hline 5 & 2000 & \textbf{B} & 15 & 10^6 & - \cr\hline 6 & 2000 & - & 16 & 10^6 & - \cr\hline 7 & 10^5 & \textbf{AB} & 17 & 10^6 & - \cr\hline 8 & 10^5 & \textbf{B} & 18 & 10^6 & - \cr\hline 9 & 10^5 & \textbf{A} & 19 & 10^6 & - \cr\hline 10 & 10^5 & - & 20 & 10^6 & - \cr\hline \end{array}$$
  • Special Property A\bf A: w=0w=0 is guaranteed.
  • Special Property B\bf B: y=0y=0 is guaranteed.

Translated by ChatGPT 5