#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 3 * 1e5 + 100, M = 500 + 10, len = 315, inf = 1e18;
const ll mod = 998244353;
ll um(ll a, ll b){
return (1LL * a * b) % mod;
}
ll subr(ll a, ll b){
return ((1LL * a - b) % mod + mod) % mod;
}
ll bp(ll x, ll step){
ll res = 1;
while(step){
if(step & 1) res = um(res, x);
x = um(x, x);
step /= 2;
}
return res;
}
ll inv(ll x){
return bp(x, mod - 2);
}
ll a[N], b[N], ax[N], bx[N], cnt[N];
vector <ll> in[N];
int main() {
//ios_base::sync_with_stdio(false);
//cin.tie(nullptr);
//cout.tie(nullptr);
ll n;
cin >> n;
map<pii, bool> mp;
for(ll i = 0; i < n; i++){
cin >> a[i] >> b[i];
ax[i] = a[i];
bx[i] = b[i];
if(mp[{a[i], b[i]}]){
return -1;
}
mp[{a[i], b[i]}] = true;
}
sort(ax, ax + n);
sort(bx, bx + n);
ll sza = unique(ax, ax + n) - ax;
ll szb = unique(bx, bx + n) - bx;
for(ll i = 0; i < n; i++){
a[i] = lower_bound(ax, ax + sza, a[i]) - ax;
b[i] = lower_bound(bx, bx + szb, b[i]) - bx;
cnt[b[i]]++;
in[a[i]].pb(b[i]);
}
ll ans = 0;
for(ll i = 0; i < sza; i++){
ll k1 = (ll)in[i].size(), sum = 0;
for(auto u : in[i]){
sum += cnt[u];
}
sum -= k1;
//cout << i << " "<< k1 << " " << sum << endl;
for(auto u : in[i]){
k1--;
ans += sum * k1;
sum = sum - cnt[u] + 1;
}
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |