#include <bits/stdc++.h>
using namespace std;
#define int long long
int N, C, X[300005], Y[300005];
map<int, vector<int> > XC, YC;
main() {
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> X[i] >> Y[i];
XC[X[i]].push_back(Y[i]);
YC[Y[i]].push_back(X[i]);
}
for (int i = 1; i <= N; i++) {
auto it = upper_bound(YC[Y[i]].begin(), YC[Y[i]].end(), X[i]), it2 = upper_bound(XC[X[i]].begin(), XC[X[i]].end(), Y[i]);
C += (YC[Y[i]].size() - (it - YC[Y[i]].begin())) * (XC[X[i]].size() - (it2 - XC[X[i]].begin()));
}
for (int i = 1; i <= N; i++) {
auto it = upper_bound(YC[Y[i]].begin(), YC[Y[i]].end(), X[i]), it2 = lower_bound(XC[X[i]].begin(), XC[X[i]].end(), Y[i]);
C += (YC[Y[i]].size() - (it - YC[Y[i]].begin())) * (it2 - XC[X[i]].begin());
}
for (int i = 1; i <= N; i++) {
auto it = lower_bound(YC[Y[i]].begin(), YC[Y[i]].end(), X[i]), it2 = upper_bound(XC[X[i]].begin(), XC[X[i]].end(), Y[i]);
C += (it - YC[Y[i]].begin()) * (XC[X[i]].size() - (it2 - XC[X[i]].begin()));
}
for (int i = 1; i <= N; i++) {
auto it = lower_bound(YC[Y[i]].begin(), YC[Y[i]].end(), X[i]), it2 = lower_bound(XC[X[i]].begin(), XC[X[i]].end(), Y[i]);
C += (it - YC[Y[i]].begin()) * (it2 - XC[X[i]].begin());
}
cout << C << '\n';
}
Compilation message
triangle.cpp:8:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |