首先可以想到用前缀和求a中小于b的元素总数,求c中大于b的元素种数,然后求满足的三元组数
然后发现二分也能做,用STL也能AC
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int n;
int cnt[N],s[N];
int a[N],b[N],c[N];
int as[N],cs[N];
int main(){
scanf("%d",&n);
for(int i = 0;i < n;++i) scanf("%d",&a[i]),a[i]++;
for(int i = 0;i < n;++i) scanf("%d",&b[i]),b[i]++;
for(int i = 0;i < n;++i) scanf("%d",&c[i]),c[i]++;
for(int i = 0;i < n;++i) cnt[a[i]]++;
for(int i = 1;i < N;++i) s[i] = s[i - 1] + cnt[i];
for(int i = 0;i < n;++i) as[i] = s[b[i] - 1];
memset(cnt,0,sizeof cnt);
memset(s,0,sizeof s);
for(int i = 0;i < n;++i) cnt[c[i]]++;
for(int i = 1;i < N;++i) s[i] = s[i - 1] + cnt[i];
for(int i = 0;i < n;++i) cs[i] = s[N - 1] - s[b[i]];
LL res = 0;
for(int i = 0;i < n;++i) res += (LL)as[i] * cs[i];
printf("%lld\n",res);
return 0;
}
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int n;
int 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(b,b + n);
sort(c,c + n);
LL res = 0;
for(int i = 0;i < n;++i){
int x = b[i];
int left,right;
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;
}
left = l;
if(a[left] >= x) left = -1;
l = 0,r = n - 1;
while(l < r){
int mid = l + r >> 1;
if(c[mid] > x) r = mid;
else l = mid + 1;
}
right = r;
if(c[right] <= x) right = n;
res += (LL)(left + 1) * (n - right);
}
printf("%lld\n",res);
return 0;
}
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int n;
int 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(b,b + n);
sort(c,c + n);
LL res = 0;
for(int i = 0;i < n;++i){
LL x = lower_bound(a,a + n,b[i]) - a;
LL y = n - (upper_bound(c,c + n,b[i]) - c);
res += x * y;
}
printf("%lld\n",res);
return 0;
}