当前位置:网站首页>递增三元组
递增三元组
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;
}
边栏推荐
- 2021GDCPC Guangdong University Student Programming Competition B.Byfibonacci
- Gxlcms有声小说系统/小说听书系统源码
- 电脑快捷方式图标变白解决方案
- DFS题单以及模板汇总
- win10重建索引
- d违反常了吗
- #yyds干货盘点# 面试必刷TOP101:判断链表中是否有环
- 【MySQL】MySQL中对数据库及表的相关操作
- go版本升级
- ML's shap: Based on FIFA 2018 Statistics (2018 Russia World Cup) team match star classification prediction data set using RF random forest + calculating SHAP value single-sample force map/dependency c
猜你喜欢
Py's pdpbox: a detailed introduction to pdpbox, installation, and case application
只会纯硬件,让我有点慌
PhpMetrics 使用
【LeetCode】42. 接雨水 - Go 语言题解
MySql统计函数COUNT详解
PyTorch模型导出到ONNX文件示例(LeNet-5)
ThinkPHP high imitation blue play cloud network disk system source code / docking easy payment system program
第十九周进度(了解物联网基础知识)
智能创意中的尺寸拓展模块
QT 在父类中添加子类的流程,object tree,
随机推荐
vulnhub靶机AI-Web-1.0渗透笔记
ML之shap:基于FIFA 2018 Statistics(2018年俄罗斯世界杯足球赛)球队比赛之星分类预测数据集利用RF随机森林+计算SHAP值单样本力图/依赖关系贡献图可视化实现可解释性之攻略
【LeetCode】55. 跳跃游戏 - Go 语言题解
【MySQL】DQL相关操作
go版本升级
【无标题】
Achievements of Science and Technology (31)
2022.7.28
抽象类和接口(学习笔记)
【LeetCode】64. 最小路径和 - Go 语言题解
MySQL联合查询(多表查询)
Debezium报错系列之二十:task failed to create new topic.Ensure that the task is authorized to create topics
PS基础学习(一)
通过社交媒体建立个人IP的 5 种行之有效的策略
grub 学习
WSL安装图形界面并通过xrdp/X-Launch访问
Apache Doris系列之:深入认识实时分析型数据库Apache Doris
通过对抗性知识蒸馏压缩深度图神经网络
Debezium error series 20: task failed to create new topic. Ensure that the task is authorized to create topics
StoneDB 为何敢称业界唯一开源的 MySQL 原生 HTAP 数据库?