#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 300100;
int x[maxn], y[maxn];
int n;
set<int>xst, yst;
map<int,int>xind, yind, cnt[maxn];
vector<int>xx[maxn], yy[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++) {
cin>>x[i]>>y[i];
xst.insert(x[i]);
yst.insert(y[i]);
}
int br = 1;
for(int i:xst) {
xind[i] = br++;
}
br = 1;
for(int i:yst) {
yind[i] = br++;
}
for(int i=1;i<=n;i++) {
x[i] = xind[x[i]];
y[i] = yind[y[i]];
xx[x[i]].pb(y[i]);
yy[y[i]].pb(x[i]);
}
for(int i=1;i<=n;i++) {
sort(yy[i].begin(), yy[i].end());
sort(xx[i].begin(), xx[i].end());
int br = 0;
for(int j:yy[i]) {
cnt[i][j] = br++;
}
}
ll result = 0LL;
for(int i=1;i<=n;i++) {
int br = 0;
for(int j:xx[i]) {
int curr_x = i;
int curr_y = j;
int lcnt = cnt[i][j];
int rcnt = yy[curr_y].size() - lcnt - 1;
int dcnt = br;
int ucnt = xx[i].size() - br - 1;
ll temp = 0LL;
temp += 1LL * lcnt * ucnt;
temp += 1LL * lcnt * dcnt;
temp += 1LL * rcnt * ucnt;
temp += 1LL * rcnt * dcnt;
result += temp;
br++;
}
}
cout<<result<<"\n";
return 0;
}
Compilation message
triangle.cpp: In function 'int main()':
triangle.cpp:58:17: warning: unused variable 'curr_x' [-Wunused-variable]
int curr_x = i;
^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
28544 KB |
Output is correct |
2 |
Correct |
25 ms |
28544 KB |
Output is correct |
3 |
Correct |
25 ms |
28544 KB |
Output is correct |
4 |
Correct |
26 ms |
28544 KB |
Output is correct |
5 |
Correct |
25 ms |
28504 KB |
Output is correct |
6 |
Correct |
28 ms |
28544 KB |
Output is correct |
7 |
Correct |
27 ms |
28580 KB |
Output is correct |
8 |
Correct |
26 ms |
28664 KB |
Output is correct |
9 |
Correct |
28 ms |
28684 KB |
Output is correct |
10 |
Correct |
30 ms |
28664 KB |
Output is correct |
11 |
Correct |
31 ms |
28792 KB |
Output is correct |
12 |
Correct |
47 ms |
30968 KB |
Output is correct |
13 |
Correct |
39 ms |
31096 KB |
Output is correct |
14 |
Correct |
62 ms |
32080 KB |
Output is correct |
15 |
Correct |
396 ms |
49144 KB |
Output is correct |
16 |
Correct |
449 ms |
50424 KB |
Output is correct |
17 |
Correct |
411 ms |
49040 KB |
Output is correct |
18 |
Correct |
407 ms |
49144 KB |
Output is correct |
19 |
Correct |
845 ms |
73468 KB |
Output is correct |
20 |
Correct |
767 ms |
62924 KB |
Output is correct |
21 |
Correct |
918 ms |
76364 KB |
Output is correct |
22 |
Correct |
1049 ms |
76284 KB |
Output is correct |