#P9715. 「QFOI R1」头

    ID: 10766 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>线性数据结构洛谷原创O2优化洛谷月赛链表

「QFOI R1」头

Background

You can take a look at this discussion: https://www.luogu.com.cn/discuss/703835.

Problem Description

Little R is a lovely girl. One day, while someone was patting her on the head, she suddenly got inspired, and casually made a problem harder for you to solve.

This problem is called the Coloring Game. Initially, you have an nn-row mm-column grid, and all cells are uncolored. There are kk brushes of different colors, with color IDs from 11 to kk. Then you are given qq operations. Each operation provides five parameters op,l,r,c,top,l,r,c,t:

  • If op=1op=1, it means coloring all cells in rows lrl\sim r with color cc.
  • If op=2op=2, it means coloring all cells in columns lrl\sim r with color cc.
  • If t=0t=0, it means that if you encounter a cell that is already colored during coloring, you stop coloring further.
  • If t=1t=1, it means that if you encounter a cell that is already colored during coloring, you overwrite it with the new color.

After all coloring operations are finished, for each color, compute how many cells are colored with that color.

Input Format

The first line contains four integers n,m,k,qn,m,k,q, representing the number of rows, columns, colors, and operations.

The next qq lines each contain five integers op,l,r,c,top,l,r,c,t, representing the parameters of this operation.

Output Format

Output one line with kk integers. The ii-th integer represents the number of cells colored with color ii.

5 5 2 4
1 2 4 1 0
2 4 5 1 1
2 2 4 2 0
1 1 1 2 1
17 7
5 5 3 6
2 1 3 3 1
2 2 4 1 0
1 4 4 2 0
2 1 1 1 0
1 2 5 2 0
1 1 5 3 0
5 4 16

Hint

Sample 11 Explanation

Use light gray to represent color 11, and gray to represent color 22.

The coloring process is shown in the figure:

There are 1717 cells colored with color 11, and 77 cells colored with color 22.


Constraints

This problem has a total of 2020 test points, each worth 55 points.

For all data, it is guaranteed that 1n,m,q2×1061\le n,m,q\le 2\times 10^6, 1k5×1051\le k\le 5\times 10^5, op{1,2}op\in\{1,2\}. If op=1op=1, then 1lrn1\le l\le r\le n; if op=2op=2, then 1lrm1\le l\le r\le m. Also, 1ck1\le c\le k, and t{0,1}t\in\{0,1\}.

  • For test points 131\sim 3: it is guaranteed that n,m,k,q200n,m,k,q\le 200.
  • For test points 464\sim 6: it is guaranteed that n,m,k,q2×103n,m,k,q\le 2\times 10^3.
  • For test points 797\sim 9: it is guaranteed that n,m,k,q105n,m,k,q\le 10^5, and op=1op=1.
  • For test points 101210\sim 12: it is guaranteed that n,m,k,q105n,m,k,q\le 10^5, and t=1t=1.
  • For test points 131813\sim 18: it is guaranteed that n,m,k,q105n,m,k,q\le 10^5.
  • For test points 192019\sim 20: there are no special constraints.

Translated by ChatGPT 5