2 条题解
-
3
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 2e5 + 10; const int INF = 0x3f3f3f3f; int n , m , a [N] , ans; signed main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a [i]; } sort (a , a + n); for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) if (a[j] - a [i] == m) ans++; //ans += (lower_bound (a + 1, a + n + 1 , a [j]) - upper_bound (a + 1, a + n + 1 , a [j])) * (lower_bound (a + 1, a + n + 1 , a [i]) - upper_bound (a + 1, a + n + 1 , a [i])); } cout << ans; return 0; }
- 1
信息
- ID
- 3005
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 4
- 标签
- 递交数
- 55
- 已通过
- 26
- 上传者