当前位置:网站首页>递增三元组
递增三元组
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;
}

边栏推荐
- 【LeetCode】42. 接雨水 - Go 语言题解
- The problem of sticky packets in tcp protocol transmission
- proemthues 服务发现配置
- Successfully solved ImportError: always import the name '_validate_lengths'
- 力扣题(2)—— 两数相加
- OpenCV笔记(二十):滤波函数——filter2D
- 力扣题(3)—— 无重复字符的最长子串
- 2021GDCPC广东省大学生程序设计竞赛 B.Byfibonacci
- PS Basic Learning (1)
- Go的Gin框架学习
猜你喜欢

$\text{ARC 145}$

Compressing Deep Graph Neural Networks via Adversarial Knowledge Distillation
![[MySQL] DQL related operations](/img/a5/c92e0404c6a970a62595bc7a3b68cd.gif)
[MySQL] DQL related operations

MySQL索引常见面试题(2022版)

Go1.18升级功能 - 泛型 从零开始Go语言

PS基础学习(一)

宁波中宁典当转让29.5%股权为283.38万元,2021年所有者权益为968.75万元

el-upload添加请求头

#Dasctf July Enabler WP

Gxlcms audio novel system/novel listening system source code
随机推荐
2022牛客暑期多校训练营1 J Serval and Essay
[0x800706D9] solution appears in Microsoft Store
第一节 zadig 入门
编码与进制
【无标题】
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
Apache Doris series: detailed steps for installation and deployment
Reverse linked list - in-place inversion method
QT开发简介、命名规范、signal&slot信号槽
力扣题(3)—— 无重复字符的最长子串
科技的成就(三十一)
IDEA使用技巧
Excel基础学习笔记
ThinkPHP high imitation blue play cloud network disk system source code / docking easy payment system program
MySql统计函数COUNT详解
Apache Doris系列之:深入认识实时分析型数据库Apache Doris
反转链表-头插反转法
reindex win10
[SAM template question] P3975 [TJOI2015] string theory
力扣题(2)—— 两数相加