#include "museum.h"
#include<algorithm>
#include<iostream>
using namespace std;
typedef struct Person {
int num,b,t,g;
};
Person P[200000];
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(),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);
int visitB[121] = {},jungbok=0;
for (int i = 0; i < N;) {
int j;
visitB[P[i].b]++;
for (j = i + 1; j < N && P[i].t == P[j].t; j++) {
ans += (j - i) - visitB[P[j].b]; jungbok += visitB[P[j].b];
visitB[P[j].b]++;
}
i = j;
}
sort(P, P + N, cmpG);
int visitBB[121] = {}, visitT[121] = {};
for (int i = 0; i < N;) {
int j;
visitBB[P[i].b]++;
visitT[P[i].t]++;
for (j = i + 1; j < N && P[i].g == P[j].g; j++) {
ans += (j - i)-visitBB[P[j].b]-visitT[P[j].t];
visitBB[P[j].b]++;
visitT[P[j].t]++;
}
i = j;
}
ans += jungbok;
return ans;
}
Compilation message
museum.cpp:5:1: warning: 'typedef' was ignored in this declaration
typedef struct Person {
^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |