아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Jailing

시간 제한10초메모리 제한512 MB

요약
격자에서 같은 값을 가진 칸들의 최소 경계 사각형을 구한 뒤, 각 사각형마다 다른 사각형과의 f 가중합을 계산해 자기 값과 XOR한 결과를 출력한다.
난이도

보통10점 중 6점

유형
구현, 행렬, 누적 합
정답자
아직 제출이 없습니다

문제

Bobo has a matrix of size n×mn \times m filled with integers. It is guaranteed that all cells which contain the same value are 44-side connected.

Let's define a jailing J_xJ\_x of a connected component with value xx as minimum-area rectangle (with sides parallel to the matrix sides) that covers all cells of the component.

For each jailing B_xB\_x, Jessica would like to find the value of

s(B_x)=∑_B_y∈A∖xf(B_x,B_y)⋅ys(B\_x)=\sum\_{B\_y \in A \setminus \\{x\\}} f(B\_x, B\_y) \cdot y

where AA is the set of all integers in the matrix and

f(B_x,B_y)={0 the area of intersection of B_x and B_y is 0 0B_x is completely inside B_y or vice versa 1Otherwisef(B\_x,B\_y)=\begin{cases} 0 & \text{ the area of intersection of } B\_x \text{ and } B\_y \text{ is } 0 \\\ 0 & B\_x \text{ is completely inside } B\_y \text{ or vice versa} \\\ 1 & \text{Otherwise} \end{cases}

입력

The input consists of several test cases terminated by end-of-file. For each test case:

The first line contains two integers nn and mm -- the size of the matrix.

The second line contains n⋅mn \cdot m integers a_1,1,a_1,2,…,a_1,ma\_{1,1}, a\_{1,2}, \ldots, a\_{1, m}, a_2,1,a_2,2,…,a_2,ma\_{2,1}, a\_{2,2}, \ldots, a\_{2, m}, …\ldots, a_n,1,a_n,2,…,a_n,ma\_{n, 1}, a\_{n, 2}, \ldots, a\_{n,m}, where a_i,ja\_{i,j} is the value in the ii-th row and the jj-th column.

출력

For each test case, output an integer denoting the value of ∑_x∈As(x)⊕x\sum\_{x \in A} s(x) \oplus x, where ⊕\oplus denotes the exclusive-or (XOR) operator.

제한

  • 1≤n⋅m≤1061 \leq n \cdot m \leq 10^6
  • 1≤a_i,j≤nm1 \leq a\_{i,j} \leq nm
  • It is guaranteed that all cells which contain the same value are 44-side connected.
  • It is guaranteed that the sum of n⋅mn \cdot m in all test cases does not exceed 10710^7.

예제1

  1. 예제 1

    입력
    4 2
    4 8 4 4 4 2 2 2
    2 7
    12 12 12 13 8 9 14 12 12 7 4 10 11 5
    3 5
    13 13 3 3 14 2 2 1 1 11 2 2 1 5 7
    
    예상 출력
    20
    93
    56