-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountRightTriangles.cpp
More file actions
39 lines (39 loc) · 1.09 KB
/
countRightTriangles.cpp
File metadata and controls
39 lines (39 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<iostream>
#include<vector>
#include<unordered_map>
#define mod 1000000007
int solve(const std::vector<int> &X, const std::vector<int> &Y){
int returnValue = 0;
std::unordered_map<int, int> hashX,hashY;
int size = X.size();
for(int index = 0;index<size;++index){
++hashX[X[index]];
}
for(int index = 0;index<size;++index){
++hashY[Y[index]];
}
for(int index = 0;index<size;++index){
int x = X[index];
int y = Y[index];
int XPointsExecptThis = hashX[x]-1;
int YPointsExceptThis = hashY[y]-1;
//std::cout<<"returnValue: "<<returnValue<<std::endl;
returnValue = ((long long)returnValue + ((long long)XPointsExecptThis * (long long)YPointsExceptThis)%mod)%mod;
}
return returnValue;
}
int main(){
int N;
std::cin>>N;
std::vector<int> X(N);
std::vector<int> Y(N);
for(int index = 0;index<N;++index){
std::cin>>X[index];
}
for(int index = 0;index<N;++index){
std::cin>>Y[index];
}
int output = solve(X,Y);
std::cout<<output<<std::endl;
return 0;
}