Eight-Shaped Figures

시간 제한5초메모리 제한2048 MB

요약
두 원이 두 점에서 만나거나 완전히 겹치지 않는 n개의 원이 주어질 때, 한 원이 다른 원 안에 완전히 들어가지 않으면서 접하는 쌍의 수를 구한다.
난이도

보통10점 중 7점

유형
기하, 정렬, 슬라이딩 윈도우, 이분 탐색
정답자
아직 제출이 없습니다

문제

Looking at problems "K-Shaped Figures" and "H-Shaped Figures" from the past two years, you took the warning seriously. You came prepared. For each of the remaining 24 letters of the alphabet, you theorized what the problem could be. You even implemented all 24 solutions and used up all of your Digital Team Reference Document space just to bring these codes to the contest. If the judges are so unoriginal that they set another problem about letter shapes, you'll just get it accepted on minute 1 and leave everyone puzzled.

What, another shapes problem? Really?! Ha-ha! Oh... wait a second...

Let's say that two circles on a plane form an 8-shaped figure if they touch each other, but neither of them lies inside the other one.

Valid 8-shaped figuresInvalid 8-shaped figures

You are given a collection of nn circles on the plane. No two circles have more than one common point. In other words, no two circles intersect twice or coincide, but they can touch or lie one within another.

Find the number of pairs of circles from this collection that form an 8-shaped figure.

입력

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn, denoting the number of circles (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5).

The ii-th of the following nn lines contains three integers x_ix\_i, y_iy\_i, and r_ir\_i, denoting the coordinates of the center of the ii-th circle and its radius (−109≤x_i,y_i≤109-10^9 \le x\_i, y\_i \le 10^9; 1≤r_i≤1091 \le r\_i \le 10^9). No two circles intersect twice or coincide, but they can touch or lie one within another.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

출력

For each test case, print the number of pairs of circles that form an 8-shaped figure.

예제1

  1. 예제 1

    입력
    2
    5
    1 1 1
    1 3 1
    3 1 1
    3 3 1
    6 7 4
    6
    -3 0 3
    -2 0 2
    -1 0 1
    1 0 1
    2 0 2
    3 0 3
    
    예상 출력
    5
    9