Atoder-3620
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 isAi, the size of the i-th middle part is Bi, and the size of the i-th lower part isCi.
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:
N
A1 … AN
B1 … BN
C1 … CN
Output
Print the number of different altars that Ringo can build.
Sample Input 1
2
1 5
2 4
3 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
3
1 1 1
2 2 2
3 3 3
Sample Output 2
27
Sample Input 3
6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288
Sample Output 3
87
题解:对上,中,下分别排序;然后对于每一个middle分别查找比他小的lower 与比他大的upper的数量
两个数相乘既得到一个middle的数量,将每一个相加即可得到max_sum的值;
AC代码为:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const int MAX = 1e5 + 10;
LL N;
LL a[MAX], b[MAX], c[MAX];
int main()
{
cin >> N;
for (int i = 1; i <= N; i++)
cin >> a[i];
for (int i = 1; i <= N; i++)
cin >> b[i];
for (int i = 1; i <= N; i++)
cin >> c[i];
sort(a + 1, a + 1 + N), sort(b + 1, b + 1 + N), sort(c + 1, c + 1 + N);
LL sum = 0;
LL ai = 0, ci = 0;
for (int i = 1; i <= N; i++)
{
while (a[ai + 1]<b[i] && ai + 1 <= N)
ai++;
while (c[ci + 1] <= b[i] && ci + 1 <= N)
ci++;
sum += ai * (N - ci);
}
cout << sum << endl;
return 0;
}
Atoder-3620的更多相关文章
- BZOJ 3670 && BZOJ 3620 && BZOJ 3942 KMP
最近感到KMP不会啊,以前都是背板的现在要理解了. #include <iostream> #include <cstring> #include <cstdio> ...
- bzoj 3620 似乎在梦中见过的样子(KMP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3620 [题意] 给定一个字符串,统计有多少形如A+B+A的子串,要求A>=K,B ...
- [BZOJ 3620] 似乎在梦中见过的样子 【KMP】
题目链接:BZOJ - 3620 题目分析 这道题使用 KMP 做 O(n^2) 的暴力就能过. 首先,我们依次枚举字串左端点 l ,然后从这个左端点开始向后做一次 KMP. 然后我们枚举右端点 r ...
- bzoj 3620 暴力KMP
十分暴力的KMP,枚举左端点,在向右侧推进的同时,取较小的la保证条件,n方暴力 #include<bits/stdc++.h> #define rep(i,j,k) for(int i= ...
- 【BZOJ 3620】 3620: 似乎在梦中见过的样子 (KMP)
3620: 似乎在梦中见过的样子 Time Limit: 15 Sec Memory Limit: 128 MBSubmit: 755 Solved: 445 Description “Madok ...
- POJ 3620 Avoid The Lakes
http://poj.org/problem?id=3620 DFS 从任意一个lake出发 重置联通的lake 并且记录 更新ans #include <iostream> #inclu ...
- 【BZOJ 3620】 似乎在梦中见过的样子
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3620 [算法] KMP [代码] #include<bits/stdc++.h ...
- [深度优先搜索] POJ 3620 Avoid The Lakes
Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8173 Accepted: 4270 D ...
- poj 3620 Avoid The Lakes(广搜,简单)
题目 找最大的一片湖的面积,4便有1边相连算相连,4角不算. runtime error 有一种可能是 数组开的太小,越界了 #define _CRT_SECURE_NO_WARNINGS #incl ...
- zoj 3620 Escape Time II dfs
题目链接: 题目 Escape Time II Time Limit: 20 Sec Memory Limit: 256 MB 问题描述 There is a fire in LTR ' s home ...
随机推荐
- FileStream相关知识分享
一.如何理解FIleStream 通过前3章的学些,相信大家对于Stream已经有一定的了解,但是又如何去理解FileStream呢?请看下图: 我们磁盘中的任何文件都是通过二进制数组组成,最为直观的 ...
- spring 是如何注入对象的和bean 创建过程分析
文章目录: beanFactory 及 bean 生命周期起步 BeanFactory refresh 全过程 BeanFactoryPostProcessor 和 BeanPostProcessor ...
- spring源码1
1.beans核心类 1.DefaultListableBeanFactory xmlBeanFactory xmlBeanFactory继承自DefaultListableBeanFactory,D ...
- LMS自适应天线阵列设计 MATLAB
在自适应天线课上刚刚学了LMS自适应阵,先出一个抢先版贴一下结果,抢先某个小朋友一步. 关于LMS的具体介绍,直接看wiki里的吧,解释的比书上简明:传送门:https://en.wikipedia. ...
- Java数组使用以及foreach循环
Java数组使用以及foreach循环 二话不说,先甩一个简单的程序: final int NUM= 10; int[] arrays = new int[NUM]; System.out.print ...
- 【集训Day1 测试】装饰
装饰(decorate) [题目描述] 一个图有 N 个结点,编号 1 至 N,有 M 条无向边,第 i 条边连接的两个结点是 Ai 和Bi,其中 Ai 和 Bi 是不同的结点.可能有多条边连接的是同 ...
- JAVA网络通信底层调用LINUX探究
前言:该博客花了我一个下午得心血,全部手打,路过给个赞,拒绝抄袭!!!!!!!!!!!!!!!!!!!!!!!!! 简单的SOCKET通信程序 先从一段简单的JAVA程序性开始写起,这里我们才用半双工 ...
- ORA-00845 startup启动不起来关于磁盘空间扩充
问题描述:今天在虚拟机下进行startup的操作,但是没有起来,系统报错:ORA-00845: MEMORY_TARGET not supported on this system 1.startup ...
- linux 正确的关机流程
查看系统的使用状态 1.使用who命令查看在线用户. 2.使用netstat -a或ss -tnl查看网络状态: 3.使用ps -aux 查看后台运行的程序. 通过上述操作可以了解系统目前使用状态,从 ...
- 折腾笔记-计蒜客t1156AC记
欢迎查看原题地址 此题思路(最初版): 暴力,得出最相近的,1000ms呢,除非数据超大,否则不超时. 说明: 爆搜,搜出结果,时间复杂度基本 $O(n^2)$ 注:本文所有时间(与空间)复杂度仅为估 ...