https://ac.2333.moe/Problem/view.xhtml?id=1723
有三个数组A,B,C,每个数组中有n个数,你可以从每个数组中找一个数,使得Ai<Bj<Ck ,(1<=I,j,k<=n)(1<=n<=100000,1<=Ai,Bj,Ck<=1000000),求最多可以组出多少三元组
Input
有多组输入
第一行输入n
接下来三行输入A,B,C三个数组,每个数组n个数
Output
每行一个整数,表示最多有多少三元组
Sample Input
3 1 1 1 2 2 2 3 3 3 3 1 2 3 1 2 3 1 2 3
Sample Output
27 1
#include<iostream>
#include<algorithm>
using namespace std;const int N = 100005;
int a[N], b[N], c[N];
int main()
{int n;while(cin >> n){long long ans = 0;for(int i = 1; i <= n; i++)scanf("%d", a+i); sort(a+1, a+n+1);for(int i = 1; i <= n; i++)scanf("%d", b+i); sort(b+1, b+n+1);for(int i = 1; i <= n; i++)scanf("%d", c+i); sort(c+1, c+n+1);for(int i = 1; i <= n; i++){int k1 = lower_bound(a+1, a+n+1, b[i]) - a;int k2 = upper_bound(c+1, c+n+1, b[i]) - c;// while(c[k2] == b[i] && k2 <= n) k2++;// cout << k1-1 << ' ' << k2 << endl;ans +=(long long) (n-k2+1)*(k1-1);}cout << ans << endl;}return 0;
}
/*
3
1 1 1
2 2 2
3 3 3
3
1 2 3
1 2 3
1 2 3
*/