当前位置:网站首页>递增三元组
递增三元组
2022-07-30 22:57:00 【Ding Jiaxiong】
题目
给定三个整数数组
A=[A1,A2,…AN],
B=[B1,B2,…BN],
C=[C1,C2,…CN],
请你统计有多少个三元组 (i,j,k) 满足:
1≤i,j,k≤N
Ai<Bj<Ck
输入格式
第一行包含一个整数 N。
第二行包含 N 个整数 A1,A2,…AN。
第三行包含 N 个整数 B1,B2,…BN。
第四行包含 N 个整数 C1,C2,…CN。
输出格式
一个整数表示答案。
数据范围
1≤N≤105,
0≤Ai,Bi,Ci≤105
输入样例:
3
1 1 1
2 2 2
3 3 3
输出样例:
27
思路分析


题解
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long LL;
const int N = 100010;
int n;
int a[N] , b[N] , c[N];
int as[N]; //as[i]表示在A中有多少个数小于B[i]
int cs[N]; //cs[i]表示在C中有多少个数大于B[i]
int cnt[N] , s[N];
int main(){
scanf("%d",&n);
//读入三个数组
for(int i = 0; i < n; i++){
scanf("%d",&a[i]);
a[i] ++;
}
for(int i = 0; i < n; i++){
scanf("%d",&b[i]);
b[i] ++;
}
for(int i = 0; i < n; i++){
scanf("%d",&c[i]);
c[i] ++;
}
//预处理
//求as[]
for(int i = 0; i < n ;i ++){
cnt[a[i]] ++;
}
//求cnt的前缀和
for(int i = 1; i < N;i ++){
s[i] = s[i - 1] + cnt[i];//求cnt的前缀和
}
//求as[]
for(int i = 0 ; i < n ; i++){
as[i] = s[b[i] - 1];
}
//求cs
//清空cnt和s
memset(cnt , 0 , sizeof cnt);
memset(s , 0 , sizeof s);
for(int i = 0; i < n;i++){
cnt[c[i]] ++ ;
}
for(int i = 1;i < N; i++){
s[i] = s[i - 1] + cnt[i];
}
//求cs
for(int i = 0 ; i < n ; i++){
cs[i] = s[N - 1] - s[b[i]];
}
//枚举每个b[i]
LL res = 0;
for(int i = 0; i < n;i++){
res += (LL)as[i] * cs[i];
}
cout << res << endl;
return 0;
}

边栏推荐
- "NIO Cup" 2022 Nioke Summer Multi-School Training Camp 2 H.Take the Elevator
- 2sk2225 Substitute 3A/1500V Chinese Documentation【PDF Data Book】
- [MySQL] DQL related operations
- Week 19 Progress (Understanding IoT Basics)
- Go语学习笔记 - gorm使用 - 表增删改查 Web框架Gin(八)
- 2021GDCPC Guangdong University Student Programming Competition B.Byfibonacci
- 通过对抗性知识蒸馏压缩深度图神经网络
- 电脑快捷方式图标变白解决方案
- MySQL索引常见面试题(2022版)
- mysql获取当前时间
猜你喜欢

Mysql进阶优化篇01——四万字详解数据库性能分析工具(深入、全面、详细,收藏备用)

Learning about XML (1)

MySQL进阶sql性能分析

2022中国物流产业大会暨企业家高峰论坛在杭州举办!

Ningbo Zhongning Pawn will transfer 29.5% of the equity for 2.8338 million yuan, and the owner's equity in 2021 will be 9.6875 million yuan

【MySQL】MySQL中对数据库及表的相关操作

mysql跨库关联查询(dblink)

反转链表-头插反转法

Apache Doris系列之:安装与部署详细步骤

2022/07/30 学习笔记 (day20) 面试题积累
随机推荐
reindex win10
[MySQL] Mysql transaction and authority management
Abstract classes and interfaces (study notes)
ZZULIOJ:1119: sequence order
ThinkPHP high imitation blue play cloud network disk system source code / docking easy payment system program
MySQL联合查询(多表查询)
WSL安装图形界面并通过xrdp/X-Launch访问
Gxlcms audio novel system/novel listening system source code
Go1.18升级功能 - 模糊测试Fuzz 从零开始Go语言
【LeetCode】55. 跳跃游戏 - Go 语言题解
2022.7.28
【MySQL】MySQL中对数据库及表的相关操作
IJCAI2022教程 | 口语语言理解:最新进展和新领域
抽象类和接口(学习笔记)
“蔚来杯“2022牛客暑期多校训练营4 L.Black Hole 垃圾计算几何
二进制序列
科技的成就(三十一)
ZZULIOJ:1119: 数列有序
第十九周进度(了解物联网基础知识)
Apache Doris series: detailed steps for installation and deployment