題號:B001 中等 hash table

CPE OJ - B001 - Pair Sum Count

來源代碼:cpeoj 時間限制:1 s

題目說明

Given an integer array $nums$ of length $n$ and a target value $k$, count the number of index pairs $(i, j)$ such that $ i< j $ and $nums[i]+ nums[j] == k$ .

輸入說明

First line: two integers $n$ and $k$ Second line: $n$ integers $nums[0..n-1]$

$$2≤n≤2×10^5$$ $$−10^9≤nums[i],k≤10^9$$

輸出說明

A single integer: the number of valid pairs. Ends with a newline

輸入輸出範例

範例輸入
5 6
1 5 3 3 2
範例輸出
2

討論

登入後即可加入討論。 登入

目前還沒有討論文章。

提交解答

登入後即可提交解答。

登入

最近提交

Joanne
C/C++ · 2026-07-01 10:36
AC
Joanne
C/C++ · 2026-07-01 10:35
PE
Yogurt
C/C++ · 2026-06-21 18:20
AC
Yogurt
C/C++ · 2026-06-11 03:29
AC
Yanru
C/C++ · 2026-06-06 18:01
AC
Yanru
C/C++ · 2026-06-06 18:01
AC
Yogurt
C/C++ · 2026-06-04 19:30
AC
Yogurt
C/C++ · 2026-06-04 16:53
AC