Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <string>
- #include <map>
- #include <set>
- #include <queue>
- #include <stack>
- #include <cstring>
- #include <algorithm>
- #define sc scanf
- #define pr printf
- #define pb push_back
- #define mp std::make_pair
- #define fr first
- #define se second
- #define sqr(i) ((i)*(i))
- #define dist(i, j) (sqr(x[i]-x[j]) + sqr(y[i]-y[j]))
- typedef std::pair<int, int> pii;
- typedef std::pair<double, double> pdd;
- const int MN = 300010;
- const int M = 1 << 30;
- const long long MAX_LONG = std::numeric_limits<long long>::max();
- const int MAX_INT = std::numeric_limits<int>::max();
- const int MIN_INT = std::numeric_limits<int>::min();
- using namespace std;
- pair<int, int> p[MN];
- map<int, int>mx;
- map<int, int>my;
- set<int> sx;
- set<int> sy;
- int main() {
- //freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
- //freopen("spantree2.in", "r", stdin); freopen("spantree2.out", "w", stdout);
- int n;
- sc("%d", &n);
- for (int i = 0; i < n; i++) {
- sc("%d%d", &p[i].fr, &p[i].se);
- mx[ p[i].fr ]++;
- my[ p[i].se ]++;
- sx.insert( p[i].fr );
- sy.insert( p[i].se );
- }
- sort(p, p + n);
- long long ans = 0;
- for(auto a : sx) {
- long long cnt = mx[a];
- ans += (cnt * (cnt - 1)) / 2;
- }
- for(auto a : sy) {
- long long cnt = my[a];
- ans += (cnt * (cnt - 1)) / 2;
- }
- for (int i = 0; i < n; ) {
- int j = i;
- while (j < n && p[i] == p[j]) j++;
- long long cnt = j - i;
- ans -= cnt * (cnt - 1) / 2;
- i = j;
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment