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

30419번 - Square Coloring 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB143327.273%

문제

There is an $n$ by $m$ chessboard with $n \times m$ squares in total. Rows and columns are numbered starting from 1ドル,ドル and the coordinates of the square in the $i$-th column and $j$-th row are denoted as $(i, j)$. Initially, all squares are white. Now, you need to perform $q$ coloring operations on this chessboard.

There are three types of coloring operations:

  • Color a horizontal line black. Specifically, given two squares $(x_1, y_1)$ and $(x_2, y_2)$ with $y_1 = y_2,ドル color all squares between (including) these two squares black.
  • Color a vertical line black. Specifically, given two squares $(x_1, y_1)$ and $(x_2, y_2)$ with $x_1 = x_2,ドル color all squares between (including) these two squares black.
  • Color a diagonal line black. Specifically, given two squares $(x_1, y_1)$ and $(x_2, y_2)$ with $x_2-x_1 = y_2-y_1$ and $x_1 \leq x_2,ドル color all squares with coordinates $(x_1+i, y_1+i)$ on the diagonal between these two squares, where 0ドル \leq i \leq x_2-x_1$. The number of times this type of coloring operation occurs is no more than 5ドル$.

Now you want to know how many black squares there are on the chessboard after performing $q$ coloring operations.

입력

The first line of input contains an integer $c,ドル which represents the test case number. If $c = 0,ドル it means that this test case is a sample test.

The second line of input contains three positive integers $n,ドル $m,ドル and $q,ドル which respectively represent the number of columns, rows, and the number of coloring operations on the chessboard.

Then $q$ lines follow, each line containing five positive integers $t, x_1, y_1, x_2, y_2$. Among them, $t = 1$ represents the first type of coloring operation, $t = 2$ represents the second type of coloring operation, and $t = 3$ represents the third type of coloring operation. $x_1, y_1, x_2, y_2$ represent the four parameters of the coloring operation.

출력

Output a line containing an integer, representing the number of black squares on the chessboard that have been colored.

제한

For all test data, it is guaranteed that: 1ドル \leq n, m \leq 10^9, 1 \leq q \leq 10^5, 1 \leq x_1, x_2 \leq n, 1 \leq y_1, y_2 \leq m,ドル and there are at most 5ドル$ operations of the third type.

예제 입력 1

0
5 5 3
1 1 3 5 3
2 3 1 3 5
3 1 1 5 5

예제 출력 1

13

In this sample test, we performed a total of three coloring operations, as shown in the following figure. The state of the chessboard after each of the three operations are given in the order from left to right.

After the first operation, squares $(1, 3),ドル $(2, 3),ドル $(3, 3),ドル $(4, 3),ドル $(5, 3)$ are colored black.

After the second operation, squares $(3, 1),ドル $(3, 2),ドル $(3, 3),ドル $(3, 4),ドル $(3, 5)$ are colored black.

After the third operation, $(1, 1),ドル $(2, 2),ドル $(3, 3),ドル $(4, 4),ドル $(5, 5)$ are colored black.

After all three coloring operations, a total of 13ドル$ squares are colored black.

힌트

추가 예제

samples.zip ​​​​​​​

출처

Olympiad > National Olympiad in Informatics (China) > NOI 2023 1번

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

출처

대학교 대회

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

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