Square Coloring

시간 제한1초메모리 제한1024 MB

요약
가로, 세로, 그리고 최대 다섯 개의 대각선 선분 색칠 연산을 수행한 뒤 n x m 판에서 검은 칸의 수를 센다.
난이도

어려움10점 중 8점

유형
구간, 정렬, 조합론, 구현
정답자
아직 제출이 없습니다

문제

There is an nn by mm chessboard with n×mn \times m squares in total. Rows and columns are numbered starting from 11, and the coordinates of the square in the ii-th column and jj-th row are denoted as (i,j)(i, j). Initially, all squares are white. Now, you need to perform qq 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)(x\_1, y\_1) and (x_2,y_2)(x\_2, y\_2) with y_1=y_2y\_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)(x\_1, y\_1) and (x_2,y_2)(x\_2, y\_2) with x_1=x_2x\_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)(x\_1, y\_1) and (x_2,y_2)(x\_2, y\_2) with x_2−x_1=y_2−y_1x\_2-x\_1 = y\_2-y\_1 and x_1≤x_2x\_1 \leq x\_2, color all squares with coordinates (x_1+i,y_1+i)(x\_1+i, y\_1+i) on the diagonal between these two squares, where 0≤i≤x_2−x_10 \leq i \leq x\_2-x\_1. The number of times this type of coloring operation occurs is no more than 55.

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

입력

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

The second line of input contains three positive integers nn, mm, and qq, which respectively represent the number of columns, rows, and the number of coloring operations on the chessboard.

Then qq lines follow, each line containing five positive integers t,x_1,y_1,x_2,y_2t, x\_1, y\_1, x\_2, y\_2. Among them, t=1t = 1 represents the first type of coloring operation, t=2t = 2 represents the second type of coloring operation, and t=3t = 3 represents the third type of coloring operation. x_1,y_1,x_2,y_2x\_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≤n,m≤109,1≤q≤105,1≤x_1,x_2≤n,1≤y_1,y_2≤m1 \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 55 operations of the third type.

예제1

  1. 예제 1

    입력
    0
    5 5 3
    1 1 3 5 3
    2 3 1 3 5
    3 1 1 5 5
    
    예상 출력
    13