8504: Shallow Moon

内存限制:128 MB 时间限制:4 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

There arem×m cells on a grid, the top-left cell is at (1,1) while the bottom-right cell is at (m,m). Initially, all the cells were colored white. Little Q has drawn n black w×h rectangles on the grid. For the i-th rectangle, Little Q chose a cell at (ai,bi), and painted all the cells (x,y) black, whereaixai+w1 and biybi+h1.

After Little Q finished all of his work, he is now wondering how many pairs of white cells are 4-connected. Please write a program to calculate:

(i,j)∣1i,jm, (i,j) is whitef(i,j)

Here f(i,j) is the number of white cells that are 4-connected with (i,j), including (i,j) itself.

Two cells are considered adjacent if and only if they share a common side. Two white cells (i,j)(x,y) are considered 4-connected if and only if there exists a sequence of white cells c1,c2,,ck such that:

  • c_1=(i,j)c1=(i,j).
  • c_k=(x,y)ck=(x,y).
  • c_i and ci+1 are adjacent for all i (1i<k).

输入格式

The first line contains a single integer T(1T1,000), the number of test cases. For each test case:

The first line contains four integers nmw and h (1n100,0001w,hm109), denoting the number of rectangles, the size of the grid, and the size of each rectangle.

Each of the next lines contains two integers ai and bi (1aimw+11bimh+1), denoting a rectangle.

It is guaranteed that the sum of all n is at most 2,000,000.

输出格式

For each test case, print a single line containing an integer denoting the answer. Note that the answer may be extremely large, so please print it modulo 2^64 instead.

输入样例 复制

1
4 6 2 2
1 3
2 2
3 5
4 1

输出样例 复制

201