当前位置:网站首页>递增三元组
递增三元组
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;
}
边栏推荐
- PhpMetrics 使用
- 反转链表-头插反转法
- win10重建索引
- [SAM模板题] P3975 [TJOI2015] 弦论
- ZZULIOJ:1119: sequence order
- Achievements of Science and Technology (31)
- Learning about XML (1)
- ML之shap:基于FIFA 2018 Statistics(2018年俄罗斯世界杯足球赛)球队比赛之星分类预测数据集利用RF随机森林+计算SHAP值单样本力图/依赖关系贡献图可视化实现可解释性之攻略
- Abstract classes and interfaces (study notes)
- "Code execution cannot continue because MSVCP140.dll was not found, reinstalling the program may resolve the problem, etc." Solutions
猜你喜欢
Abstract classes and interfaces (study notes)
StoneDB 为何敢称业界唯一开源的 MySQL 原生 HTAP 数据库?
Week 19 Progress (Understanding IoT Basics)
2sk2225代换3A/1500V中文资料【PDF数据手册】
可视化工具Netron介绍
Apache Doris series: detailed steps for installation and deployment
$\text{ARC 145}$
# Dasctf 7月赋能赛 WP
Go语学习笔记 - gorm使用 - gorm处理错误 Web框架Gin(十)
2022中国物流产业大会暨企业家高峰论坛在杭州举办!
随机推荐
#yyds干货盘点# 面试必刷TOP101:判断链表中是否有环
StoneDB 为何敢称业界唯一开源的 MySQL 原生 HTAP 数据库?
A detailed explanation: SRv6 Policy model, calculation and drainage
PyTorch model export to ONNX file example (LeNet-5)
2022牛客暑期多校训练营1 J Serval and Essay
反转链表-头插反转法
【MySQL】MySQL中对数据库及表的相关操作
go版本升级
Golang go-redis cluster模式下不断创建新连接,效率下降问题解决
Regular expression syntax and usage
关于XML的学习(一)
ThinkPHP high imitation blue play cloud network disk system source code / docking easy payment system program
【LeetCode】55. 跳跃游戏 - Go 语言题解
2022.7.27
#Dasctf July Enabler WP
电脑快捷方式图标变白解决方案
【Untitled】
【LeetCode】70. 爬楼梯 - Go 语言题解
Golang 切片删除指定元素的几种方法
grub learning