Skip to content

Commit c04d863

Browse files
authored
Create 3623. Count Number of Trapezoids I (#947)
2 parents 47b25fc + 9404eb1 commit c04d863

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

3623. Count Number of Trapezoids I

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
};

0 commit comments

Comments
 (0)