标签:
#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> using namespace std; typedef long long LL; #define CLR(x,y) memset((x),(y),sizeof((x))) #define FOR(x,y,z) for(int (x)=(y);(x)<(z);++(x)) #define FORD(x,y,z) for(int (x)=(y);(x)>=(z);--(x)) #define FOR2(x,y,z) int (x);for((x)=(y);(x)<(z);++(x)) #define FORD2(x,y,z) int (x);for((x)=(y);(x)>=(z);--(x)) const int maxn = 200000 + 10; struct Point{ int x,y; bool operator == (const Point & a)const { return a.x==x && a.y == y; } }p[maxn]; bool cmp1(Point & a,Point & b){ return a.x < b.x || (a.x == b.x && a.y < b.y); } bool cmp2(Point & a,Point & b){ return a.y < b.y || (a.y == b.y && a.x < b.x); } int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int n;LL ans = 0; scanf("%d",&n); FOR(i,0,n) scanf("%d%d",&p[i].x,&p[i].y); sort(p,p+n,cmp1); for(int i = 0;i < n ;){ int cnt = 0; FOR2(j,i,n){ if(p[j].x == p[i].x) ++cnt; else break; } ans += (long long)1 * (cnt - 1)*cnt/2; i = j; } sort(p,p+n,cmp2); for(int i = 0;i < n ;){ int cnt = 0; FOR2(j,i,n){ if(p[j].y == p[i].y) ++cnt; else break; } ans += (long long)1*(cnt - 1)*cnt/2; i = j; } for(int i = 0;i < n ;){ int cnt = 0; FOR2(j,i,n){ if(p[j] == p[i]) ++cnt; else break; } ans -= (long long)1*(cnt - 1)*cnt/2; i = j; } printf("%I64d\n",ans); return 0; } |
[2016-03-08][codeforces][651][C][Watchmen]
标签:
原文地址:http://www.cnblogs.com/qhy285571052/p/5263917.html