제출 #149107

#제출 시각아이디문제언어결과실행 시간메모리
149107etyu (#200)함수컵 박물관 (FXCUP4_museum)C++17
100 / 100
156 ms7528 KiB
#include "museum.h"
#include <algorithm>

struct ts
{
	int a, b, c;
	bool operator<(const ts &r) {
		if (a != r.a) return a < r.a;
		if (b != r.b) return b < r.b;
		return c < r.c;
	}
};

ts p[200009];

long long CountSimilarPairs(std::vector<int> B, std::vector<int> T, std::vector<int> G) {
	int N = B.size();
	for (int i = 0; i < N; i++) {
		p[i].a = B[i]; p[i].b = T[i]; p[i].c = G[i];
	}
	long long ans = 0;
	std::sort(p, p + N);
	int c1 = 0, c2 = 0, c3 = 0;
	for (int i = 0; i < N; i++) {
		c1++; c2++; c3++;
		if (i == N - 1 || p[i].a != p[i + 1].a) {
			ans += 1LL * c1 * (c1 - 1) / 2LL;
			c1 = 0;
		}
		if (i == N - 1 || p[i].a != p[i + 1].a || p[i].b != p[i + 1].b) {
			ans -= 1LL * c2 * (c2 - 1) / 2LL;
			c2 = 0;
		}
		if (i == N - 1 || p[i].a != p[i + 1].a || p[i].b != p[i + 1].b || p[i].c != p[i + 1].c) {
			ans += 1LL * c3 * (c3 - 1) / 2LL;
			c3 = 0;
		}
		std::swap(p[i].b, p[i].c); std::swap(p[i].c, p[i].a);
	}
	for (int ti = 0; ti < 2; ti++) {
		std::sort(p, p + N);
		c1 = c2 = 0;
		for (int i = 0; i < N; i++) {
			c1++; c2++;
			if (i == N - 1 || p[i].a != p[i + 1].a) {
				ans += 1LL * c1 * (c1 - 1) / 2LL;
				c1 = 0;
			}
			if (i == N - 1 || p[i].a != p[i + 1].a || p[i].b != p[i + 1].b) {
				ans -= 1LL * c2 * (c2 - 1) / 2LL;
				c2 = 0;
			}
			std::swap(p[i].b, p[i].c); std::swap(p[i].c, p[i].a);
		}
	}
	return ans;
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...