#P14049. [SDCPC 2019] Tokens on the Segments

[SDCPC 2019] Tokens on the Segments

题目描述

Consider nn segments on a two-dimensional plane, where the endpoints of the ii-th segment are (li,i)(l_i, i) and (ri,i)(r_i, i). One can put as many tokens as he likes on the integer points of the plane (recall that an integer point is a point whose xx and yy coordinates are both integers), but the xx coordinates of the tokens must be different from each other.

What's the maximum possible number of segments that have at least one token on each of them?

输入格式

The first line of the input contains an integer TT (about 100100), indicating the number of test cases. For each test case:

The first line contains one integer nn (1n1051 \le n \le 10^5), indicating the number of segments.

For the next nn lines, the ii-th line contains 2 integers li,ril_i, r_i (1liri1091 \le l_i \le r_i\le 10^9), indicating the xx coordinates of the two endpoints of the ii-th segment.

It's guaranteed that at most 55 test cases have n100n \ge 100.

输出格式

For each test case output one line containing one integer, indicating the maximum possible number of segments that have at least one token on each of them.

2
3
1 2
1 1
2 3
3
1 2
1 1
2 2
3
2

提示

For the first sample test case, one can put three tokens separately on (1,2),(2,1)(1, 2), (2, 1) and (3,3)(3, 3).

For the second sample test case, one can put two tokens separately on (1,2)(1, 2) and (2,3)(2, 3).