问题 J: Snuke Festival

问题 J: Snuke Festival

时间限制: 1 Sec  内存限制: 128 MB
提交: 895  解决: 197
[提交] [状态] [讨论版] [命题人:admin]

题目描述

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.

样例输入

2
1 5
2 4
3 6

样例输出

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


今年的斯努克节又来了。首先,Ringo将举行一个仪式来召唤Snuke。在仪式上,他需要一个祭坛,它由三个部分组成,一个在三个类别中:一个,上、中、下。
他有三个类别中的每一个部分。第i个上部的尺寸为AI,第i个中间部分的尺寸为Bi,第i个下部的尺寸为Ci。
为了建造祭坛,中间部分的尺寸必须严格大于上部,下部的尺寸必须大于中间部分的尺寸。另一方面,满足这些条件的任何三个部分都可以组合在一起形成祭坛。
林格能建多少座祭坛?这里,当使用的三个部分中的至少一个不同时,两个祭坛被认为是不同的。

这是百度翻译

给你三个数组,在每个数组里选一个数,满足a<b<c(a∈A,b∈B,c∈C)问有多少种选法

注意到有一句当使用的三部分中至少一个不同时,两祭坛个被认为不同,然后就死了

(各种去重操作那叫一个666,死的莫名其妙,删掉去重操作就过了。。。)

举个栗子

1,2

2,2

3,3

这样选出来是1,2,3,那么有两个2按照那句话应该看成相同的,也就是说要去重的。。

不管了,说下思路

我是用的sort一下然后两个前缀和来做的

B【i】存的是对于当前的b【i】在c数组中有几个比它大的,

那么对于一个A【i】要求的便是大于a【i】的所有b【i】对应的B【i】的和

答案应该是所有A【i】的和,那么其实A【i】便不用开数组了,直接加就好

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int a[100005];
int b[100005];
int c[100005];
int A[100005];
int B[100005];
bool cmp(int a,int b){return a>b;}
int main(){
    int n;
    scanf("%d",&n);
    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,cmp),sort(b,b+n,cmp),sort(c,c+n,cmp);
 
    int flag = 0;
    ll cnt = 0;
    for(int i=0;i<n;i++)
    {
        while(flag<n&&c[flag]>b[i])
        {
            cnt++;
            flag++;
        }
        B[i]=cnt;
        //printf("%d    %lld\n",i,cnt);
    }
    cnt = flag = 0;
    ll ans = 0;
    for(int i=0;i<n;i++)
    {
        while(flag<n && b[flag]>a[i])
        {
            cnt += B[flag];
            flag++;
        }
        ans += cnt;
        //printf("%d    %lld\n",i,cnt);
    }
 
    printf("%lld\n",ans);
 
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Du_Mingm/article/details/81392454