cswork / OA打开练习工作台

RobloxOA #16

Find Number of Valid Pairs

估计中等评测数据准备中,可先阅读题面

考点(AI 标注)哈希计数

Imagine you have two long lists of numbers, let’s call them a and b, and they are exactly the same length. Your goal is to find special pairs of positions, (i, j), where i is smaller than j, and something interesting happens between the numbers at these positions. For each pair, you’re looking for this magical balance: When you take the number from list a at position i and subtract the number from list b at position j, it should be equal to what you get when you take the number from list a at position j and subtract the number from list b at position i. Your task is to figure out how many such special pairs exist in these two lists.

Example 1

Input:

a = [2, -2, 5, 3]
b = [1, 5, -1, 1]

Output:

6

Explanation: see the problem source section below for the original explanation ;)