codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

2009D.md (1657B)


      1 Source: https://codeforces.com/problemset/problem/2009/D
      2 
      3 D. Satyam and Counting
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Satyam is given $n$ distinct points on the 2D coordinate plane. It is guaranteed that $0 \leq y_i \leq 1$ for all given points $(x_i, y_i)$. How many different nondegenerate right triangles$^{\text{∗}}$ can be formed from choosing three different points as its vertices?
     22 
     23 Two triangles $a$ and $b$ are different if there is a point $v$ such that $v$ is a vertex of $a$ but not a vertex of $b$.
     24 
     25 $^{\text{∗}}$A nondegenerate right triangle has positive area and an interior $90^{\circ}$ angle.
     26 
     27 Input
     28 
     29 The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.
     30 
     31 The first line of each test case contains an integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) — the number of points.
     32 
     33 The following $n$ lines contain two integers $x_i$ and $y_i$ ($0 \leq x_i \leq n$, $0 \leq y_i \leq 1$) — the $i$'th point that Satyam can choose from. It is guaranteed that all $(x_i, y_i)$ are pairwise distinct.
     34 
     35 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
     36 
     37 Output
     38 
     39 Output an integer for each test case, the number of distinct nondegenerate right triangles that can be formed from choosing three points.
     40 
     41 Example
     42 
     43 Input
     44 
     45 ```
     46 3
     47 
     48 5
     49 
     50 1 0
     51 
     52 1 1
     53 
     54 3 0
     55 
     56 5 0
     57 
     58 2 1
     59 
     60 3
     61 
     62 0 0
     63 
     64 1 0
     65 
     66 3 0
     67 
     68 9
     69 
     70 1 0
     71 
     72 2 0
     73 
     74 3 0
     75 
     76 4 0
     77 
     78 5 0
     79 
     80 2 1
     81 
     82 7 1
     83 
     84 8 1
     85 
     86 9 1
     87 ```
     88 
     89 Output
     90 
     91 ```
     92 4
     93 0
     94 8
     95 ```
     96 
     97 Note
     98 
     99 The four triangles in question for the first test case:
    100 
    101  ![](https://espresso.codeforces.com/fa3d2396b9917bde3bc09a850f594ce163b55803.png)