This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "museum.h"
#include <algorithm>
struct data {
int b, t, g;
};
bool cmp1(const data& a, const data& b) {
if (a.b < b.b) return true;
if (a.b == b.b) {
if (a.t < b.t) return true;
if (a.t == b.t) return a.g < b.g;
}
return false;
}
bool cmp2(const data& a, const data& b) {
if (a.t < b.t) return true;
if (a.t == b.t) {
if (a.g < b.g) return true;
if (a.g == b.g) return a.b < b.b;
}
return false;
}
bool cmp3(const data& a, const data& b) {
if (a.g < b.g) return true;
if (a.g == b.g) {
if (a.b < b.b) return true;
if (a.b == b.b) return a.t < b.t;
}
return false;
}
std::vector<data> V;
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++) {
V.push_back({B[i], T[i], G[i]});
}
long long res = 0;
std::sort(V.begin(), V.end(), cmp1);
long long cnt1=1, cnt2=1, cnt3=1;
for (int i=1; i<N; i++) {
if (V[i].b == V[i-1].b) {
cnt1++;
if (V[i].t == V[i-1].t) {
cnt2++;
if (V[i].g == V[i-1].g) {
cnt3++;
} else {
res += cnt3*(cnt3-1)/2;
cnt3=1;
}
} else {
res -= cnt2*(cnt2-1)/2;
res += cnt3*(cnt3-1)/2;
cnt2=cnt3=1;
}
} else {
res += cnt1*(cnt1-1)/2;
res -= cnt2*(cnt2-1)/2;
res += cnt3*(cnt3-1)/2;
cnt1=cnt2=cnt3=1;
}
}
res += cnt1*(cnt1-1)/2;
res -= cnt2*(cnt2-1)/2;
res += cnt3*(cnt3-1)/2;
cnt1=cnt2=cnt3=1;
std::sort(V.begin(), V.end(), cmp2);
for (int i=1; i<N; i++) {
if (V[i].t == V[i-1].t) {
cnt1++;
if (V[i].g == V[i-1].g) {
cnt2++;
} else {
res -= cnt2*(cnt2-1)/2;
cnt2=1;
}
} else {
res += cnt1*(cnt1-1)/2;
res -= cnt2*(cnt2-1)/2;
cnt1=cnt2=1;
}
}
res += cnt1*(cnt1-1)/2;
res -= cnt2*(cnt2-1)/2;
cnt1=cnt2=1;
std::sort(V.begin(), V.end(), cmp3);
cnt1=1, cnt2=1, cnt3=1;
for (int i=1; i<N; i++) {
if (V[i].g == V[i-1].g) {
cnt1++;
if (V[i].b == V[i-1].b) {
cnt2++;
} else {
res -= cnt2*(cnt2-1)/2;
cnt2=1;
}
} else {
res += cnt1*(cnt1-1)/2;
res -= cnt2*(cnt2-1)/2;
cnt1=cnt2=1;
}
}
res += cnt1*(cnt1-1)/2;
res -= cnt2*(cnt2-1)/2;
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |