#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
const int mod = 1e9+7, N = 2e5+5;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val);}
int a[N], n, m, k;
map<int, vector<int>> X, Y;
void solve(int test_case){
int i, j;
cin >> n;
vector<pii> tmp;
for(i=0;i<n;i++){
int x, y;
cin >> x >> y;
Y[x].pb(y);
X[y].pb(x);
tmp.pb({x, y});
}
int ans = 0;
for(auto &[t, tt] : X)sort(all(tt));
for(auto &[t, tt] : Y)sort(all(tt));
for(auto [x, y] : tmp){
int itx = lower_bound(all(X[y]), x)-X[y].begin();
int ity = lower_bound(all(Y[x]), y)-Y[x].begin();
int bx = X[y].size()-itx-1;
int by = Y[x].size()-ity-1;
ans += bx*by;
ans += bx*ity;
ans += itx*by;
ans += itx*ity;
}
cout << ans << '\n';
return;
}
signed main(){
FASTIO;
#define MULTITEST 0
#if MULTITEST
int ___T;
cin >> ___T;
for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
solve(T_CASE);
#else
solve(1);
#endif
return 0;
}
Compilation message
triangle.cpp: In function 'void solve(long long int)':
triangle.cpp:17:9: warning: unused variable 'j' [-Wunused-variable]
17 | int i, j;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
14 ms |
1896 KB |
Output is correct |
13 |
Correct |
13 ms |
1896 KB |
Output is correct |
14 |
Correct |
22 ms |
2664 KB |
Output is correct |
15 |
Correct |
320 ms |
12380 KB |
Output is correct |
16 |
Correct |
342 ms |
13020 KB |
Output is correct |
17 |
Correct |
308 ms |
12656 KB |
Output is correct |
18 |
Correct |
316 ms |
12380 KB |
Output is correct |
19 |
Correct |
1004 ms |
28244 KB |
Output is correct |
20 |
Correct |
715 ms |
19540 KB |
Output is correct |
21 |
Correct |
1028 ms |
28384 KB |
Output is correct |
22 |
Correct |
1036 ms |
28244 KB |
Output is correct |