Atcoder Regular Contest 084 Snuke Festival

题目链接http://arc084.contest.atcoder.jp/tasks/arc084_a

题意:给你三个数组,每个数组中各选一个数组成一个三元组,要求要递增,问这样的三元组有多少个。

思路:第一个和第三个数组离散化以后映射到一个权值数组上然后计算前缀和,表示到i位置为止前面有多少个数字,然后枚举b数组里的元素统计一下a数组中比当前元素小的和c数组中比当前元素大的个数之积就可以了。

#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
const int INF=0x3f3f3f3f;
const int P=1000000007;
const double PI=acos(-1.0);
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
int n;
int a[maxn],b[maxn],c[maxn];
vector<int>vec;
ll ma[maxn*3],mc[maxn*3];
int main(){
    read(n);
    for (int i=1;i<=n;i++) read(a[i]),vec.push_back(a[i]);
    for (int i=1;i<=n;i++) read(b[i]),vec.push_back(b[i]);
    for (int i=1;i<=n;i++) read(c[i]),vec.push_back(c[i]);
    sort(vec.begin(),vec.end());
    vec.erase(unique(vec.begin(),vec.end()),vec.end());
    for (int i=1;i<=n;i++){
        int pos=lower_bound(vec.begin(),vec.end(),a[i])-vec.begin();
        pos++;
        ma[pos]++;
    }
    for (int i=1;i<=n;i++){
        int pos=lower_bound(vec.begin(),vec.end(),c[i])-vec.begin();
        pos++;
        mc[pos]++;
    }
    for (int i=1;i<=3e5;i++) ma[i]+=ma[i-1],mc[i]+=mc[i-1];
    ll ans=0;
    for (int i=1;i<=n;i++){
        int pos=lower_bound(vec.begin(),vec.end(),b[i])-vec.begin();
        pos++;
        ans+=ma[pos-1]*(mc[300000]-mc[pos]);
    }
    cout<<ans<<endl;
    return 0;
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注