#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n; cin >> n;
vector<array<array<int, 2>, 2>> cnt(n);
array<map<int, vector<array<int, 2>>>, 2> mp;
for (int i = 0; i < n; ++i) {
int x, y; cin >> x >> y;
mp[0][x].push_back({y, i});
mp[1][y].push_back({x, i});
}
for (auto it : {0, 1}) {
for (auto [x, a] : mp[it]) {
sort(a.begin(), a.end());
for (int i = 0; i < a.size(); ) {
int j = i;
while (j < a.size() && a[j][0] == a[i][0]) {
++j;
}
array<int, 2> v = {i, int(a.size()) - j};
while (i < j) {
cnt[a[i++][1]][it] = v;
}
}
}
}
long long res = 0;
for (int i = 0; i < n; ++i) {
for (int x = 0; x < 2; ++x) {
for (int y = 0; y < 2; ++y) {
res += (long long) cnt[i][0][x] * cnt[i][1][y];
}
}
}
cout << res;
return 0;
}
Compilation message
triangle.cpp: In function 'int main()':
triangle.cpp:25:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int i = 0; i < a.size(); ) {
| ~~^~~~~~~~~~
triangle.cpp:27:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | while (j < a.size() && a[j][0] == a[i][0]) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
5 ms |
1880 KB |
Output is correct |
13 |
Correct |
5 ms |
2004 KB |
Output is correct |
14 |
Correct |
8 ms |
2652 KB |
Output is correct |
15 |
Correct |
77 ms |
12380 KB |
Output is correct |
16 |
Correct |
87 ms |
12884 KB |
Output is correct |
17 |
Correct |
81 ms |
12344 KB |
Output is correct |
18 |
Correct |
84 ms |
12368 KB |
Output is correct |
19 |
Correct |
224 ms |
24944 KB |
Output is correct |
20 |
Correct |
154 ms |
19336 KB |
Output is correct |
21 |
Correct |
229 ms |
26468 KB |
Output is correct |
22 |
Correct |
218 ms |
26544 KB |
Output is correct |