Snuke Festival(AtCoder-3620)

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

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
int a[N],b[N],c[N];
int main() {
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
        scanf("%d",&b[i]);
    for(int 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);

    LL res=0;
    LL ja=0,jc=0;
    for(int i=1;i<=n;i++){
        while(a[ja+1]<b[i]&&ja+1<=n)//满足a[i]<b[i]的个数
            ja++;
        while(c[jc+1]<=b[i]&&jc+1<=n)//不满足b[i]<c[i]的个数
            jc++;
        res+=ja*(n-jc);
    }
    printf("%lld\n",res);

    return 0;
}

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值