#include "museum.h"
#include<algorithm>
#include<utility>
#include<map>
#include<iostream>
using namespace std;
typedef struct Person {
int num,b,t,g;
};
Person P[212121];
bool cmpB(Person A, Person B) {
return A.b < B.b;
}
bool cmpT(Person A, Person B) {
return A.t < B.t;
}
bool cmpG(Person A, Person B) {
return A.g < B.g;
}
long long CountSimilarPairs(std::vector<int> B, std::vector<int> T, std::vector<int> G) {
int N = B.size();
long long ans = 0;
for (int i = 0; i < N; i++) {
P[i].num = i;
P[i].b = B[i];
P[i].t = T[i];
P[i].g = G[i];
}
sort(P, P + N, cmpB);
for (int i = 0; i < N;) {
int j;
for (j = i + 1; j < N && P[i].b==P[j].b;j++) {
ans += (j-i);
}
i = j;
}
sort(P, P + N, cmpT);
for (int i = 0; i < N;) {
int j;
int visitB[121] = {};
visitB[P[i].b]++;
for (j = i + 1; j < N && P[i].t == P[j].t; j++) {
ans += (j - i) - visitB[P[j].b];
visitB[P[j].b]++;
}
i = j;
}
sort(P, P + N, cmpG);
for (int i = 0; i < N;) {
int j;
int visitB[121] = {}, visitT[121] = {};
map<pair<int, int>,int> m;
visitB[P[i].b]++;
visitT[P[i].t]++;
m[make_pair(P[i].b, P[i].t)]++;
for (j = i + 1; j < N && P[i].g == P[j].g; j++) {
ans += (j - i) -visitT[P[j].t]-visitB[P[j].b]+m[make_pair(P[j].b, P[j].t)];
visitB[P[j].b]++;
visitT[P[j].t]++;
m[make_pair(P[j].b, P[j].t)]++;
}
i = j;
}
return ans;
}
Compilation message
museum.cpp:7:1: warning: 'typedef' was ignored in this declaration
typedef struct Person {
^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
10 ms |
512 KB |
Output is correct |
9 |
Correct |
7 ms |
512 KB |
Output is correct |
10 |
Correct |
7 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
10 ms |
512 KB |
Output is correct |
9 |
Correct |
7 ms |
512 KB |
Output is correct |
10 |
Correct |
7 ms |
384 KB |
Output is correct |
11 |
Correct |
10 ms |
640 KB |
Output is correct |
12 |
Correct |
20 ms |
1408 KB |
Output is correct |
13 |
Correct |
58 ms |
2676 KB |
Output is correct |
14 |
Correct |
75 ms |
3696 KB |
Output is correct |
15 |
Correct |
119 ms |
5360 KB |
Output is correct |
16 |
Correct |
98 ms |
8296 KB |
Output is correct |
17 |
Correct |
120 ms |
8296 KB |
Output is correct |
18 |
Correct |
182 ms |
8296 KB |
Output is correct |
19 |
Correct |
189 ms |
8296 KB |
Output is correct |
20 |
Correct |
187 ms |
8424 KB |
Output is correct |