Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using lli = long long;
- using pll = pair <lli, lli>;
- const int N = 2e5;
- const lli INF = 2e18;
- int main(){
- int n;
- lli ans = 0;
- scanf("%d", &n);
- map <lli, int> same;
- vector <pll> point1, point2;
- for(int i=1;i<=n;i++){
- lli x, y;
- scanf("%lld%lld", &x, &y);
- same[y] ++;
- point1.push_back({x, y});
- point2.push_back({y, x});
- }
- sort(point1.begin(), point1.end());
- sort(point2.begin(), point2.end());
- lli prev = -INF;
- lli cnt = 0;
- for(auto p: point1){
- lli x, y;
- x = p.first;
- y = p.second;
- if(prev == -INF){
- prev = x;
- cnt = 1;
- continue;
- }
- if(prev == x){
- cnt ++;
- }
- else {
- if(cnt > 1) ans += (lli)(cnt)*(cnt-1) / 2;
- prev = x;
- cnt = 1;
- }
- }
- if(cnt > 1) ans += (lli)(cnt)*(cnt-1) / 2;
- lli prey = -INF, prex = -INF;
- cnt = 0;
- lli h = 1;
- vector <lli> X;
- for(auto p: point2){
- lli x, y;
- y = p.first;
- x = p.second;
- if(prey == -INF){
- prey = y;
- prex = x;
- cnt = 1;
- continue;
- }
- if(prey == y){
- if(prex == x) cnt ++;
- else {
- X.push_back(cnt);
- cnt = 1;
- }
- }
- else {
- X.push_back(cnt);
- int sz = X.size();
- for(int i=0;i<sz-1;i++){
- for(int j=i+1;j<sz;j++){
- ans += (lli) X[i]*X[j];
- }
- }
- if(sz != 0) X.clear();
- cnt = 1;
- }
- prex = x;
- prey = y;
- }
- X.push_back(cnt);
- int sz = X.size();
- for(int i=0;i<sz-1;i++){
- for(int j=i+1;j<sz;j++){
- ans += (lli) X[i]*X[j];
- }
- }
- printf("%lld", ans);
- return 0;
- }
- /**
- 4
- 1 2
- 1 2
- 1 3
- 4 2
- 3
- 1 1
- 7 5
- 1 5
- 6
- 0 0
- 0 1
- 0 2
- -1 1
- 0 1
- 1 1
- 7
- 1 2
- 1 2
- 1 2
- 1 3
- 1 3
- 4 2
- 4 2
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement