#P11103. [2016杭电多校]Counting Intersections

    ID: 10245 传统题 6000ms 256MiB 尝试: 1 已通过: 1 难度: 5 上传者: 标签>CF1700扫描线树状数组排序计算几何数据结构

[2016杭电多校]Counting Intersections

Counting Intersections

Problem Description

Given some segments which are paralleled to the coordinate axis. You need to count the number of their intersection. The input data guarantee that no two segments share the same endpoint, no covered segments, and no segments with length 0.

Input

The first line contains an integer T, indicates the number of test case. The first line of each test case contains a number n(1<=n<=100000), the number of segments. Next n lines, each with for integers, x1, y1, x2, y2, means the two endpoints of a segment. The absolute value of the coordinate is no larger than 1e9.

Output

For each test case, output one line, the number of intersection.

Sample Input

2
4
1 0 1 3
2 0 2 3
0 1 3 1
0 2 3 2
4
0 0 2 0
3 0 3 2
3 3 1 3
0 3 0 2

Sample Output

4
0

Author

BUPT

Source

2016 Multi-University Training Contest 10