UPC6615: Snuke Festival

6615: Snuke Festival

时间限制: 1 Sec  内存限制: 128 MB
提交: 908  解决: 203
[提交] [状态] [讨论版] [命题人: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

来源/分类

ABC077&ARC084 

小结:小结啥。。。这题我现在都有意见最后一句话总干画蛇添足。。。影响我的判断。。

题意:就是给三组数要求第一组比第二组小,第二组比第三组小问有多少种解决方式。。。这题最后一句话我总觉得是如果数一样就算一种啊好奇怪都理解成下标不同就可以,去重后检查了n遍输了n组示例都没找到hack点。。。最后一问结果说下标不同????没啥可说的 枚举中间的数,二分查找。复习一下lower_bound跟upper_bound

lower_bound:有序数列查找到第一个大于等于的数

upper_bound:有序数列查找到第一个大于的数

复杂度:nlogn

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define FIN freopen("D://code//in.txt", "r", stdin)
#define ppr(i,x,n) for(int i = x;i <= n;i++)
#define rpp(i,n,x) for(int i = n;i >= x;i--)
const double eps = 1e-6;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
 
inline int read() {//读入挂
    int ret = 0, c, f = 1;
    for(c = getchar(); !(isdigit(c) || c == '-'); c = getchar());
    if(c == '-') f = -1, c = getchar();
    for(; isdigit(c); c = getchar()) ret = ret * 10 + c - '0';
    if(f < 0) ret = -ret;
    return ret;
}
ll a[maxn],b[maxn],c[maxn];
set <ll> C;
int main()
{
    ll n;
    ll ans = 0;
    scanf("%lld",&n);
    ppr(i,1,n){scanf("%lld",a+i);}
    ppr(i,1,n){scanf("%lld",b+i);}
    ppr(i,1,n){scanf("%lld",c+i);}
    sort(a+1,a+1+n);
    sort(b+1,b+1+n);
    sort(c+1,c+1+n);
    ppr(i,1,n)
    {
        ll x = lower_bound(a+1,a+1+n,b[i]) - a;
        ll y = upper_bound(c+1,c+1+n,b[i]) - c;
        x--;y--;
        y = n-y;
        ans += x*y;
    }
    printf("%lld\n",ans);
    return 0;
 } 

猜你喜欢

转载自blog.csdn.net/Pandapan1997/article/details/81393313