当前位置:   article > 正文

Snuke Festival(AtCoder-3620)

snuke festival

Problem Description

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≤iN)
  • 1≤Bi≤109(1≤iN)
  • 1≤Ci≤109(1≤iN)
  • 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.

Example

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

题意:有三组数 ai、bi、ci,其中每组数个数都是 n,要求在这三组数中各选择一个数,使得 ai<bi<ci,问有多少种情况

思路:单纯的暴力有三重循环,由于 n 最大到 1E5,一定会超时,那么可以考虑在枚举 b 的同时设置双指针,同时比较 a、c,记录当前情况下合法的数量,同时为了遍历方便,可以考虑对立事件的做法

Source Program

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<string>
  5. #include<cstring>
  6. #include<cmath>
  7. #include<ctime>
  8. #include<algorithm>
  9. #include<utility>
  10. #include<stack>
  11. #include<queue>
  12. #include<vector>
  13. #include<set>
  14. #include<map>
  15. #include<bitset>
  16. #define EPS 1e-9
  17. #define PI acos(-1.0)
  18. #define INF 0x3f3f3f3f
  19. #define LL long long
  20. const int MOD = 1E9+7;
  21. const int N = 100000+5;
  22. const int dx[] = {-1,1,0,0,-1,-1,1,1};
  23. const int dy[] = {0,0,-1,1,-1,1,-1,1};
  24. using namespace std;
  25. int a[N],b[N],c[N];
  26. int main() {
  27. int n;
  28. scanf("%d",&n);
  29. for(int i=1;i<=n;i++)
  30. scanf("%d",&a[i]);
  31. for(int i=1;i<=n;i++)
  32. scanf("%d",&b[i]);
  33. for(int i=1;i<=n;i++)
  34. scanf("%d",&c[i]);
  35. sort(a+1,a+1+n);
  36. sort(b+1,b+1+n);
  37. sort(c+1,c+1+n);
  38. LL res=0;
  39. LL ja=0,jc=0;
  40. for(int i=1;i<=n;i++){
  41. while(a[ja+1]<b[i]&&ja+1<=n)//满足a[i]<b[i]的个数
  42. ja++;
  43. while(c[jc+1]<=b[i]&&jc+1<=n)//不满足b[i]<c[i]的个数
  44. jc++;
  45. res+=ja*(n-jc);
  46. }
  47. printf("%lld\n",res);
  48. return 0;
  49. }

 

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号