codeforces-scrape

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

1520D.md (945B)


      1 Source: https://codeforces.com/problemset/problem/1520/D
      2 
      3 D. Same Differences
      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 You are given an array $a$ of $n$ integers. Count the number of pairs of indices $(i, j)$ such that $i \lt j$ and $a_j - a_i = j - i$.
     22 
     23 Input
     24 
     25 The first line contains one integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
     26 
     27 The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$).
     28 
     29 The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) — array $a$.
     30 
     31 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
     32 
     33 Output
     34 
     35 For each test case output the number of pairs of indices $(i, j)$ such that $i \lt j$ and $a_j - a_i = j - i$.
     36 
     37 Example
     38 
     39 Input
     40 
     41 ```
     42 4
     43 6
     44 3 5 1 4 6 6
     45 3
     46 1 2 3
     47 4
     48 1 3 3 4
     49 6
     50 1 6 3 4 5 6
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 1
     57 3
     58 3
     59 10
     60 ```