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≤iN)
  • 1≤Bi≤109(1≤iN)
  • 1≤Ci≤109(1≤iN)
  • 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的更多相关文章

  1. BZOJ 3670 && BZOJ 3620 && BZOJ 3942 KMP

    最近感到KMP不会啊,以前都是背板的现在要理解了. #include <iostream> #include <cstring> #include <cstdio> ...

  2. bzoj 3620 似乎在梦中见过的样子(KMP)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3620 [题意] 给定一个字符串,统计有多少形如A+B+A的子串,要求A>=K,B ...

  3. [BZOJ 3620] 似乎在梦中见过的样子 【KMP】

    题目链接:BZOJ - 3620 题目分析 这道题使用 KMP 做 O(n^2) 的暴力就能过. 首先,我们依次枚举字串左端点 l ,然后从这个左端点开始向后做一次 KMP. 然后我们枚举右端点 r  ...

  4. bzoj 3620 暴力KMP

    十分暴力的KMP,枚举左端点,在向右侧推进的同时,取较小的la保证条件,n方暴力 #include<bits/stdc++.h> #define rep(i,j,k) for(int i= ...

  5. 【BZOJ 3620】 3620: 似乎在梦中见过的样子 (KMP)

    3620: 似乎在梦中见过的样子 Time Limit: 15 Sec  Memory Limit: 128 MBSubmit: 755  Solved: 445 Description “Madok ...

  6. POJ 3620 Avoid The Lakes

    http://poj.org/problem?id=3620 DFS 从任意一个lake出发 重置联通的lake 并且记录 更新ans #include <iostream> #inclu ...

  7. 【BZOJ 3620】 似乎在梦中见过的样子

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3620 [算法] KMP [代码] #include<bits/stdc++.h ...

  8. [深度优先搜索] POJ 3620 Avoid The Lakes

    Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8173   Accepted: 4270 D ...

  9. poj 3620 Avoid The Lakes(广搜,简单)

    题目 找最大的一片湖的面积,4便有1边相连算相连,4角不算. runtime error 有一种可能是 数组开的太小,越界了 #define _CRT_SECURE_NO_WARNINGS #incl ...

  10. 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 ...

随机推荐

  1. Python OpenCV4趣味应用系列(四)---颜色物体实时检测

    今天,我们来实现一个视频实时检测颜色物体的小实例,视频中主要有三个颜色物体,我们只检测红色和绿色的球状物体,如下图所示: 第一步需要打开视频(或者摄像头): cap = cv2.VideoCaptur ...

  2. 如何在 PHP 和 Laravel 中使用 Traits

    事实上,PHP 作为一门编程语言存在的问题之一,就是你只能使用单继承.这意味着一个类只能从另一个类中继承.例如,可能希望从几个不同的类继承方法,以防止代码重复.在 PHP 5.4 中 一个新的语言特性 ...

  3. [Error]使用了未经检查或不安全的操作...

    编译错误注: MethodReflect.java使用了未经检查或不安全的操作.注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译. 解决:在类前面加入下面一句解决 @Suppr ...

  4. C语言程序设计100例之(14):丑数

    例14   丑数 问题描述 丑数是其质因子只可能是2,3或5的数.前10个丑数分别为1, 2, 3, 4, 5, 6, 8, 9, 10, 12.输入一个正整数n,求第n个丑数. 输入格式 每行为一个 ...

  5. nyoj 1112 求次数 (map)

    求次数 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 题意很简单,给一个数n 以及一个字符串str,区间[i,i+n-1] 为一个新的字符串,i 属于[0,strl ...

  6. 力扣(LeetCode)颠倒二进制位 个人题解

    颠倒给定的 32 位无符号整数的二进制位. 示例 1: 输入: 00000010100101000001111010011100 输出: 0011100101111000001010010100000 ...

  7. 微调(Fine-tune)原理

    在自己的数据集上训练一个新的深度学习模型时,一般采取在预训练好的模型上进行微调的方法.什么是微调?这里已VGG16为例进行讲解,下面贴出VGGNet结构示意图. 上面圈出来的是VGG16示意图,也可以 ...

  8. ArcGIS 发布Feature服务

    运行环境: Win10 ArcGIS10.4 具体操作: 1.打开ArcMap,加载sde中导入的文件,也可以加载shp数据源指向sde中文件 2.保存成mxd,然后点share as-Service ...

  9. 2019-11-7:sql注入防御,webshell概念,学习笔记

    sql注入防护GPC,magic_quotes_gpc函数在php中的作用是判断解析用户提示的数据,如包括有:post.get.cookie过来的数据增加转义字符“\”,以确保这些数据不会引起程序,特 ...

  10. python 实现图片批量加入水印!pillow 入门实战!

    写文章的时候可以设置是否添加水印.可是,有些图片可能想加水印,有些不想加水印,该怎么办呢? 配置环境 python3 + pillow pip3 install pillow 引入库 from PIL ...