题目描述
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 <iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[200000],b[200000],c[200000],d[200000];
int main()
{
long long int i,n,m=0,j,k,l,x=0,y=0;
scanf("%lld",&n);
for(i=1; i<=n; i++)
{
scanf("%d",&a[i]);
}
for(i=1; i<=n; i++)
{
scanf("%d",&b[i]);
}
for(i=1; i<=n; i++)
{
scanf("%d",&c[i]);
}
sort(a+1,a+1+n);
sort(b+1,b+1+n);
sort(c+1,c+1+n);
for(i=n;i>=1;i--)
{
k=upper_bound(c+1,c+1+n,b[i])-c;
if(k<=n)
{
d[i]=d[i+1]+n-k+1;
}
}
for(i=1;i<=n;i++)
{
k=upper_bound(b+1,b+1+n,a[i])-b;
if(k>n)
{
break;
}else
{
m+=d[k];
}
}
printf("%lld",m);
return 0;
}