File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ #include <bits/stdc++.h>
2+ using namespace std;
3+
4+ class Solution {
5+ public:
6+ int countTrapezoids(vector<vector<int>>& points) {
7+ const long long MOD = 1000000007LL;
8+ const long long INV2 = (MOD + 1) / 2;
9+
10+ unordered_map<long long, int> freq;
11+ freq.reserve(points.size() * 2);
12+ for (auto &p : points) {
13+ long long y = p[1];
14+ ++freq[y];
15+ }
16+
17+ long long sumF = 0;
18+ long long sumF2 = 0;
19+
20+ for (auto &kv : freq) {
21+ long long c = kv.second;
22+ if (c >= 2) {
23+ long long f = c * (c - 1) / 2 % MOD;
24+ sumF = (sumF + f) % MOD;
25+ sumF2 = (sumF2 + f * f % MOD) % MOD;
26+ }
27+ }
28+
29+ long long ans = (sumF * sumF) % MOD;
30+ ans = (ans - sumF2 + MOD) % MOD;
31+ ans = ans * INV2 % MOD;
32+
33+ return (int)ans;
34+ }
35+ };
You can’t perform that action at this time.
0 commit comments