6615: Snuke Festival
题目描述
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.
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
int b[100005];
int a[100005];
int c[100005];
int main()
{
int n;
while(~scanf("%d",&n))
{
long long sum=0;
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);
int x=0,y=0,numa=0,numc=n;
for(int i=0;i<n;i++)
{
while(b[i]>a[x]&&x<n)
{
x++;
numa++;
}
while(b[i]>=c[y]&&y<n)
{
y++;
numc--;
}
sum+=(long long)numa*numc;
}
printf("%lld\n",sum);
}
return 0;
}