二分好题
注意当找不出来的时候特判一下
// 找出小于b[i]的最大数,大于b[i]的最小数
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 100005;
typedef long long LL;
int n, a[N], b[N], c[N];
int main(){
scanf("%d", &n);
for(int i = 0; i < n; i ++ ) scanf("%d", &a[i]);
for(int i = 0; i < n; i ++ ) scanf("%d", &b[i]);
for(int i = 0; i < n; i ++ ) scanf("%d", &c[i]);
sort(a, a + n);
sort(c, c + n);
LL sum = 0;
for(int i = 0; i < n; i ++ ){
int x = b[i];
int l = 0, r = n - 1;
while(l < r){
int mid = l + r + 1 >> 1;
if(a[mid] < x) l = mid;
else r = mid - 1;
}
int p = l + 1;
if(a[l] >= x) p = 0;
l = 0, r = n - 1;
while(l < r){
int mid = l + r >> 1;
if(c[mid] > x) r = mid;
else l = mid + 1;
}
int q = n - l;
if(c[l] <= x) q = 0;
// cout << i << " " << p * q << endl;
sum += (LL)p * q;
}
printf("%lld\n", sum);
return 0;
}
// 3
// 1 4 5
// 9 5 5
// 4 6 7
// 3 * 0
// 2 * 2
// 2 * 2