#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N;
cin >> N;
vector<int> X(N), Y(N);
for (int i = 0; i < N; i++) {
cin >> X[i] >> Y[i];
}
map<int, vector<int>> pos_x, pos_y;
for (int i = 0; i < N; i++) {
pos_x[X[i]].push_back(Y[i]);
pos_y[Y[i]].push_back(X[i]);
}
long long answer = 0;
for (int i = 0; i < N; i++) {
int px = lower_bound(pos_x[X[i]].begin(), pos_x[X[i]].end(), Y[i]) - pos_x[X[i]].begin();
int xs = (int)pos_x[X[i]].size();
int py = lower_bound(pos_y[Y[i]].begin(), pos_y[Y[i]].end(), X[i]) - pos_y[Y[i]].begin();
int ys = (int)pos_y[Y[i]].size();
answer += 1LL * px * py + 1LL * px * (ys - 1 - py) + 1LL * (xs - 1 - px) * py + 1LL * (xs - 1 - px) * (ys - 1 - py);
}
cout << answer << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 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 |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
8 ms |
1628 KB |
Output is correct |
13 |
Correct |
8 ms |
1888 KB |
Output is correct |
14 |
Correct |
14 ms |
2396 KB |
Output is correct |
15 |
Correct |
149 ms |
10440 KB |
Output is correct |
16 |
Correct |
170 ms |
10984 KB |
Output is correct |
17 |
Correct |
151 ms |
10324 KB |
Output is correct |
18 |
Correct |
151 ms |
10320 KB |
Output is correct |
19 |
Correct |
443 ms |
19284 KB |
Output is correct |
20 |
Correct |
302 ms |
15508 KB |
Output is correct |
21 |
Correct |
456 ms |
20428 KB |
Output is correct |
22 |
Correct |
471 ms |
20328 KB |
Output is correct |