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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node {
int a,b,c;
bool operator < (const node &n) const {
if(a == n.a) {
if(b == n.b) return c < n.c;
return b < n.b;
}
return a < n.a;
}
bool operator == (const node &n) const {
return a == n.a && b==n.b && c==n.c;
}
};
vector<node> a,b,c,d,e,f,g;
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++) {
a.push_back({B[i],-1,-1});
}
for(int i=0;i<n;i++) {
b.push_back({-1,T[i],-1});
}
for(int i=0;i<n;i++) {
c.push_back({-1,-1,G[i]});
}
for(int i=0;i<n;i++) {
d.push_back({B[i],T[i],-1});
}
for(int i=0;i<n;i++) {
e.push_back({B[i],-1,G[i]});
}
for(int i=0;i<n;i++) {
f.push_back({-1,T[i],G[i]});
}
for(int i=0;i<n;i++) {
g.push_back({B[i],T[i],G[i]});
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
sort(c.begin(), c.end());
sort(d.begin(), d.end());
sort(e.begin(), e.end());
sort(f.begin(), f.end());
sort(g.begin(), g.end());
ll ret = 0;
ll cnt = 0;
node bf = {-1,-1,-1};
for(int i=0;i<n;i++) {
if(bf == a[i]) {
cnt++;
} else {
ret += cnt * (cnt-1) / 2;
cnt = 1;
bf = a[i];
}
}
ret += cnt * (cnt-1) / 2;
cnt = 0;
bf = {-1,-1,-1};
for(int i=0;i<n;i++) {
if(bf == b[i]) {
cnt++;
} else {
ret += cnt * (cnt-1) / 2;
cnt = 1;
bf = b[i];
}
}
ret += cnt * (cnt-1) / 2;
cnt = 0;
bf = {-1,-1,-1};
for(int i=0;i<n;i++) {
if(bf == c[i]) {
cnt++;
} else {
ret += cnt * (cnt-1) / 2;
cnt = 1;
bf = c[i];
}
}
ret += cnt * (cnt-1) / 2;
cnt = 0;
bf = {-1,-1,-1};
for(int i=0;i<n;i++) {
if(bf == d[i]) {
cnt++;
} else {
ret -= cnt * (cnt-1) / 2;
cnt = 1;
bf = d[i];
}
}
ret -= cnt * (cnt-1) / 2;
cnt = 0;
bf = {-1,-1,-1};
for(int i=0;i<n;i++) {
if(bf == e[i]) {
cnt++;
} else {
ret -= cnt * (cnt-1) / 2;
cnt = 1;
bf = e[i];
}
}
ret -= cnt * (cnt-1) / 2;
cnt = 0;
bf = {-1,-1,-1};
for(int i=0;i<n;i++) {
if(bf == f[i]) {
cnt++;
} else {
ret -= cnt * (cnt-1) / 2;
cnt = 1;
bf = f[i];
}
}
ret -= cnt * (cnt-1) / 2;
cnt = 0;
bf = {-1,-1,-1};
for(int i=0;i<n;i++) {
if(bf == g[i]) {
cnt++;
} else {
ret += cnt * (cnt-1) / 2;
cnt = 1;
bf = g[i];
}
}
ret += cnt * (cnt-1) / 2;
return ret;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |