Atcoder arc 084 C
来源:互联网 发布:c语言标识符可分为 编辑:程序博客网 时间:2024/06/01 17:48
题目链接:http://arc084.contest.atcoder.jp/tasks/arc084_a
C - Snuke Festival
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
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
Input is given from Standard Input in the following format:
NA1 … ANB1 … BNC1 … CN
Output
Print the number of different altars that Ringo can build.
Sample Input 1
21 52 43 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
31 1 12 2 23 3 3
Sample Output 2
27
Sample Input 3
63 14 159 2 6 5358 9 79 323 84 62643 383 2 79 50 288
Sample Output 3
87
解析:这个题显然不能用O(n^2)或者O(n^3),只能O(n*log(n)),这里就想到了前缀和
代码:
#include<bits/stdc++.h>using namespace std;typedef long long LL; const int N = 100009; int a[N], b[N], c[N];LL f[N]; 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); sort(b, b+n); sort(c, c+n); LL ans = 0; for(int i = 0; i < n; i++) { if(b[i] >= c[n-1]) break; f[i+1] = 1ll*n - (upper_bound(c, c+n, b[i]) - c); } f[0] = 0; for(int i = 1; i <= n; i++) f[i] += f[i-1]; for(int i = 0; i < n; i++) { if(a[i] >= b[n-1]) break; int s = upper_bound(b, b+n, a[i]) - b; ans += f[n] - f[s]; } printf("%lld\n", ans); return 0; }
- Atcoder arc 084 C
- Atcoder ARC 077 C
- Atcoder arc 084 D
- Atcoder ARC 077 D
- Atcoder ARC 077 E
- Atcoder ARC 077 F
- [DP]Atcoder ARC 087 D
- Atcoder ARC 71D 井井井 / ### 公式化简
- NYOJ-117/atcoder ARC 75-E
- atcoder 1th C
- AtCoder 2286 C
- AtCoder 2282 C
- atcoder AtCoder Regular Contest 084 D
- Atcoder Grand Contest 013C
- AtCoder Beginner Contest 059 C
- AtCoder Regular Contest 077-C
- AtCoder Grand Contest 017 C
- AtCoder Regular Contest 078-C
- scala 从控制台读取用户输入(新) Console.readLine已过时
- Python高级编程-如何根据字典中值得大小,对字典中的项排序
- HDU6222Little Boxes
- ccs的三种颜色格式
- sdut 2136 数据结构实验之二叉树的建立与遍历
- Atcoder arc 084 C
- 项目管理学习总结(10)——项目经理需要具备8点管理素质
- 第二章:reactNative开发中模拟器的配置
- Codeforces Round #438
- 天梯地图(30 分)
- leetcode problem solve 2——Add Two Numbers
- [JZOJ5454]仔细的检查
- Python高级编程-如何让字典保持有序?
- loj #6062. 「2017 山东一轮集训 Day2」Pair(线段树)