Test instructions: Bishop on the same diagonal (that's right. =) will attack each other and seek the logarithm of each other.
Since there are positive and negative diagonal lines, the X-y and x+y written by each bishop are saved with two arrays respectively.
And then scan each array for the repeating number k ans plus kC2 on the line.
WA took two rounds because it didn't take into account that if the entire array was duplicated, the last amount was added once.
#include <cstdio>#include<cmath>#include<cstring>#include<queue>#include<vector>#include<algorithm>#defineINF 0x3f3f3f3f#defineMem (str,x) memset (str, (x), sizeof (str))#defineSTOP puts ("Pause");using namespaceStd;typedefLong LongLL;intN, node[200010], node2[200010]; LL ans;intMain () {ans=0; scanf ("%d", &N); for(inti =1; I <= N; i++){ intx, y; scanf ("%d%d", &x, &y); Node[i]= X-y; Node2[i]= x +y; } Sort (Node+1, node +1+N); Sort (Node2+1, Node2 +1+N); LL Count=1; for(inti =2; I <= N; i++){ if(Node[i] = = node[i-1]) count++; Else{ans+ = (count * (Count-1) /2); Count=1; }} ans+ = (count * (Count-1) /2); Count=1; for(inti =2; I <= N; i++){ if(Node2[i] = = node2[i-1]) count++; Else{ans+ = (count * (Count-1) /2); Count=1; }} ans+ = (count * (Count-1) /2); printf ("%i64d\n", ans); return 0;}
Codeforces Round #341 Div.2 B. Wet Shark and Bishops