#include <bits/stdc++.h>
typedef long long ll;
#define mp make_pair
#define F first
#define S second
using namespace std;
using pii = pair<int,int>;
const int N = 3e5 + 5;
pii p[N];
int cp[2][N], m[2];
ll cnt[2][N];
int pos(int t, int x){ return lower_bound(cp[t], cp[t]+m[t], x) - cp[t];}
signed main(){
int n; scanf("%d", &n);
for(int i = 0, x, y; i<n; ++i){
scanf("%d %d", &x, &y);
p[i] = mp(x, y);
cp[0][m[0]++] = x;
cp[1][m[1]++] = y;
}
for(int j = 0; j<2; ++j) sort(cp[j], cp[j]+m[j]), m[j] = unique(cp[j], cp[j]+m[j]) - cp[j];
for(int i = 0; i<n; ++i) ++cnt[0][pos(0, p[i].F)], ++cnt[1][pos(1, p[i].S)];
ll tot = 0;
for(int i = 0; i<n; ++i){
int x = pos(0, p[i].F), y = pos(1, p[i].S);
tot += (cnt[0][x] - 1) * (cnt[1][y] - 1);
}
printf("%lld", tot);
}
Compilation message
triangle.cpp: In function 'int main()':
triangle.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | int n; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
triangle.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 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 |
1 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 |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
620 KB |
Output is correct |
13 |
Correct |
5 ms |
1112 KB |
Output is correct |
14 |
Correct |
6 ms |
860 KB |
Output is correct |
15 |
Correct |
65 ms |
4648 KB |
Output is correct |
16 |
Correct |
67 ms |
4868 KB |
Output is correct |
17 |
Correct |
64 ms |
4444 KB |
Output is correct |
18 |
Correct |
63 ms |
4420 KB |
Output is correct |
19 |
Correct |
184 ms |
11268 KB |
Output is correct |
20 |
Correct |
137 ms |
8372 KB |
Output is correct |
21 |
Correct |
208 ms |
11860 KB |
Output is correct |
22 |
Correct |
206 ms |
11856 KB |
Output is correct |