Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Point {
- int x;
- int y;
- public Point(int x, int y) {
- this.x = x;
- this.y = y;
- }
- }
- void solve() {
- int n = in.nextInt();
- Point[] points = new Point[n];
- for (int i = 0; i < n; i++) {
- int x = in.nextInt();
- int y = in.nextInt();
- points[i] = new Point(x, y);
- }
- Arrays.sort(points, (p1, p2) -> Integer.compare(p1.x, p2.x));
- long countx = 0;
- long ans = 0;
- for (int i = 1; i < n; i++) {
- if (points[i].x == points[i - 1].x) {
- countx++;
- if (i == n - 1){
- ans += (countx * (countx + 1)) / 2;
- countx = 0;
- }
- } else {
- ans += (countx * (countx + 1)) / 2;
- countx = 0;
- }
- }
- Arrays.sort(points, (o1, o2) -> {
- if (o1.y < o2.y)
- return -1;
- if (o1.y > o2.y)
- return 1;
- if (o1.x < o2.x)
- return -1;
- if (o1.x > o2.x)
- return 1;
- return 0;
- });
- long county = 0;
- long dec = 0;
- for (int i = 1; i < n; i++) {
- if (points[i].y == points[i - 1].y) {
- county++;
- if (points[i].x == points[i - 1].x) {
- dec++;
- }
- if (i == n - 1){
- ans += (county * (county + 1)) / 2 - (dec*(dec+1))/2;
- county = 0;
- dec = 0;
- }
- } else {
- ans += (county * (county + 1)) / 2 - (dec*(dec+1))/2;
- county = 0;
- dec = 0;
- }
- }
- out.print(ans);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement