solution.cpp 1.2 KB
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#include <iostream>
#include <cstring>

using namespace std;

typedef long long LL;

const int N = 1e5 + 10;
int a[N], b[N], c[N], sa[N], sc[N], s[N]; //sa是用来记录a<b[i]得前缀和,sc是用来记录c>b[i]的前缀和,s是临时数组。

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i], a[i]++; //++操作是为了防止输入为0,a[i]++使得s[a[i]]++不可能为0,使得s[i]+=s[i-1]可以计算,又因为且所有增大相当于所有不增大。
    for (int i = 0; i < n; i++)
        cin >> b[i], b[i]++;
    for (int i = 0; i < n; i++)
        cin >> c[i], c[i]++;

    for (int i = 0; i < n; i++)
        s[a[i]]++; //a[i]出现数字的次数被统计。
    for (int i = 1; i < N; i++)
        s[i] += s[i - 1]; //1到i为止的出现的总次数
    for (int i = 0; i < n; i++)
        sa[i] = s[b[i] - 1]; //1-b[i]的从次数

    memset(s, 0, sizeof s);

    for (int i = 0; i < n; i++)
        s[c[i]]++;
    for (int i = 1; i < N; i++)
        s[i] += s[i - 1];
    for (int i = 0; i < n; i++)
        sc[i] = s[N - 1] - s[b[i]]; //n到b[i]的总次数

    LL res = 0;
    for (int i = 0; i <= n; i++)
        res += (LL)sa[i] * sc[i];
    cout << res;
}