muntasir007

Untitled

Mar 7th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <cstdio>
  2. #include <bits/stdc++.h>
  3. long long int ncr ( int n, int r) {
  4. if(r==0) return (long long)1;
  5. else if(n==r) return (long long)1;
  6. else return (long long)ncr(n-1,r-1)+ncr(n-1,r);
  7. }
  8. using namespace std;
  9. int main () {
  10. map <int, int> xx, yy;
  11. pair <int, int> xxx;
  12. map < pair <int, int> , int> paira;
  13. int n, x, y, i;
  14. scanf("%d", &n);
  15. int ara[n][2];
  16. for (i=0; i<n; i++) {
  17. scanf("%d %d", &x, &y);
  18. xx[x]++;
  19. yy[y]++;
  20. xxx.first = x;
  21. xxx.second = y;
  22. paira[xxx]++;
  23. ara[i][0] = x;
  24. ara[i][1] = y;
  25. }
  26. long long int one=0, two=0, three=0, ans = 0;
  27.  
  28. for (i=0; i<n; i++) {
  29. if (xx[ara[i][0]] > 1) {
  30. one+= ncr(xx[ara[i][0]], 2);
  31. xx[ara[i][0]] = 0;
  32. }
  33. if (yy[ara[i][1]] > 1) {
  34. two += ncr (yy[ara[i][1]], 2);
  35. yy [ara[i][1]] = 0;
  36. }
  37. xxx.first = ara[i][0];
  38. xxx.second = ara[i][1];
  39. if (paira[xxx] > 1) {
  40. three += ncr (paira[xxx], 2);
  41. paira[xxx]=0;
  42. }
  43. }
  44.  
  45. printf("%I64d\n", one+two - three);
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment