cswork / OA打开练习工作台

SnowflakeOA #17

Perfect Pairs

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

考点(AI 标注)双指针滑窗二分查找位运算

A pair of integers (x, y) is perfect if both of the following conditions are met: min(|x - y|, |y - x|) ≤ min(|x|, |y|) max(|x - y|, |y - x|) > max(|x|, |y|) Given an array arr of length n, find the number of perfect pairs (arr[i], arr[j]) where 0 ≤ i Function Description Complete the function getPerfectPairsCountin the editor below.getPerfectPairsCount` has the following parameter:

  • int arr[n]: an array of integers Returns int: the number of perfect pairs

Constraints

  • 2 ≤ n ≤ 2*10⁵
  • -10⁹ ≤ arr[i] ≤ 10⁹