Atoder-3620

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 isAi, the size of the i-th middle part is Bi, and the size of the i-th lower part isCi.

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

  • 1N105
  • 1Ai109(1iN)
  • 1Bi109(1iN)
  • 1Ci109(1iN)
  • All input values are integers.
Input

Input is given from Standard Input in the following format:

N
A1  AN
B1  BN
C1  CN
Output

Print the number of different altars that Ringo can build.

Sample Input 1

2
1 5
2 4
3 6
Sample Output 1

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
Sample Input 2

3
1 1 1
2 2 2
3 3 3
Sample Output 2

27
Sample Input 3

6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288
Sample Output 3

87


题解:对上,中,下分别排序;然后对于每一个middle分别查找比他小的lower 与比他大的upper的数量

两个数相乘既得到一个middle的数量,将每一个相加即可得到max_sum的值;

AC代码为:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;


typedef long long LL;
const int MAX = 1e5 + 10;
LL N;
LL a[MAX], b[MAX], c[MAX];


int main()
{
cin >> N;
for (int i = 1; i <= N; i++)
cin >> a[i];
for (int i = 1; i <= N; i++)
cin >> b[i];
for (int i = 1; i <= N; i++)
cin >> c[i];
sort(a + 1, a + 1 + N), sort(b + 1, b + 1 + N), sort(c + 1, c + 1 + N);


LL sum = 0;
LL ai = 0, ci = 0;
for (int i = 1; i <= N; i++)
{
while (a[ai + 1]<b[i] && ai + 1 <= N)
ai++;
while (c[ci + 1] <= b[i] && ci + 1 <= N)
ci++;
sum += ai * (N - ci);
}


cout << sum << endl;


return 0;
}



posted @ 2018-03-04 22:45  StarHai  阅读(157)  评论(0编辑  收藏  举报