题目描述
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.
He has N parts for each of the three categories. The size of the i-th upper part is Ai, the size of the i-th middle part is Bi, and the size of the i-th lower part is Ci.
To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
Constraints
1≤N≤105
1≤Ai≤109(1≤i≤N)
1≤Bi≤109(1≤i≤N)
1≤Ci≤109(1≤i≤N)
All input values are integers.
输入
Input is given from Standard Input in the following format:
N
A1 … AN
B1 … BN
C1 … CN
输出
Print the number of different altars that Ringo can build.
样例输入
2 1 5 2 4 3 6
样例输出
3
提示
The following three altars can be built:
Upper: 1-st part, Middle: 1-st part, Lower: 1-st part
Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part
Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part
#include<math.h>
#include<algorithm>
#include <iostream>
using namespace std;
typedef long long int LL;
const int N=1e5+5;
int a[N];
int b[N];
int c[N];
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n;i++)
cin>>b[i];
for(int i=0;i<n;i++)
cin>>c[i];
sort(a,a+n);
sort(b,b+n);
sort(c,c+n);
LL j=0;//用于统计第一部分里面小于第二部分的个数
LL k=0;//用于统计第三部分里面小于第二部分的个数
LL sum=0;
for(int i=0;i<n;i++){
while(a[j]<b[i]&&j<n){
j++;
}
while(c[k]<=b[i]&&k<n){
k++;
}
sum+=(j*(n-k));
}
cout<<sum<<endl;
return 0;
}
本文介绍了一个关于如何计算可以构建的不同祭坛数量的问题。通过给定的三个数组,分别代表上部、中部和下部祭坛部件的大小,文章详细阐述了如何确保中部部件大于上部、下部部件大于中部的情况下,计算所有可能的不同组合。
501

被折叠的 条评论
为什么被折叠?



