D - Distinct Trio
D - Distinct Trio
题意:求三个数个各不相同的数目。
题解:正面考虑比较困难,可以反向思考,在总值上减去不符合的即可
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int N=5e5+50;
ll a[N];
ll sum[N],d,vis[N];
vector<ll> q;
ll solve(ll y){
return y*(y-1)*(y-2)/6;
}
signed main(){
ll n;cin>>n;
for(ll i=1;i<=n;i++){
cin>>a[i]; sum[a[i]]++;
if(vis[a[i]])continue;
vis[a[i]]=1;q.push_back(a[i]);
}
ll ans=solve(n);
for(ll i=0;i<q.size();i++){
if(sum[q[i]]>=2) ans-=sum[q[i]]*(sum[q[i]]-1)*(n-sum[q[i]])/2;
if(sum[q[i]]>=3) ans-=solve(sum[q[i]]);
}
cout<<ans;
}
D - Distinct Trio的更多相关文章
- [LeetCode] Longest Substring with At Most K Distinct Characters 最多有K个不同字符的最长子串
Given a string, find the length of the longest substring T that contains at most k distinct characte ...
- [LeetCode] Longest Substring with At Most Two Distinct Characters 最多有两个不同字符的最长子串
Given a string S, find the length of the longest substring T that contains at most two distinct char ...
- [LeetCode] Distinct Subsequences 不同的子序列
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- SQL中distinct的用法
SQL中distinct的用法 1.作用于单列 2.作用于多列 3.COUNT统计 4.distinct必须放在开头 5.其他 在表中,可能会包含重复值.这并不成问题,不过,有时您也许希望仅仅列出 ...
- Oracle 查询语句(where,order by ,like,in,distinct)
select * from production;alter table production add productionprice number(7,2); UPDATE production s ...
- mysql中distinct的用法
本事例实验用表task,结构如下 MySQL> desc task; +-------------+------------+------+-----+-------------------+- ...
- Distinct Subsequences
https://leetcode.com/problems/distinct-subsequences/ Given a string S and a string T, count the numb ...
- distinct 与 group by 去重
例如下表格:表名:fruit id Name Price Num 1 西瓜 10 2 2 西瓜 11 2 3 香蕉 10 3 4 桃子 10 2 当我想获取Name不重复的数据,结果如下 id Nam ...
- 大数据下的Distinct Count(二):Bitmap篇
在前一篇中介绍了使用API做Distinct Count,但是精确计算的API都较慢,那有没有能更快的优化解决方案呢? 1. Bitmap介绍 <编程珠玑>上是这样介绍bitmap的: B ...
随机推荐
- python requires模块 https请求 由于TLS协议版本太高导致错误
错误提示 requests.exceptions.SSLError: HTTPSConnectionPool(host='air.cnemc.cn', port=18007): Max retries ...
- python中 OS模块中 os.path.join() 函数用法简介
基础用法 os.path.join() 用于拼接文件的路径,可以传入多个待拼接的路径 若各个路径之间不存在 " / ", 则其会自动为各个路径之间增加连接符 " / &q ...
- 1.3 操作系统的第三个功能——存储管理功能 -《zobolの操作系统学习札记》
1.3 操作系统的第三个功能--存储管理功能 作者zobol:关于操作系统概论-存储管理功能,我给出下列问题: 目录 1.3 操作系统的第三个功能--存储管理功能 问1:操作系统的文件管理系统主要是负 ...
- 《Java笔记——基础语法》
Java笔记--基础语法 一.字符串的拼接: 例如: System.out.println(""+""); 二.换行语句: 例如: Syst ...
- JavaScript中用画布canvans做贪吃蛇
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 如何通过WinDbg获取方法参数值
引入 我们在调试的过程中,经常会通过查看方法的输入与输出来确定这个方法是否异常.那么我们要怎么通过 WinDbg 来获取方法的参数值呢? WinDbg 中主要包含三种命令:标准命令.元命令(以 . 开 ...
- Cf #782 (Div. 2)
A. Red Versus Blue 题意 共有 n 个连续字符 ,其中有 a 个 R ,b 个 B (a+b=n),问怎么排列使 R 的最大连续个数最小,输出一种可能排列 思路 b 个B可以把a个 ...
- 自己写雪花算法IdWorker
package com.aiyusheng.shopping.util; import java.lang.management.ManagementFactory; import java.net. ...
- 揭开服务网格~Istio Service Mesh神秘的面纱
目录 一.写在前面 二.微服务与K8S 三.服务网格与K8S 四.常见的产品 五.Istio架构 六.Istio的核心资源介绍 6.1.VirtualService 6.2.Destination R ...
- jsx/tsx使用cssModule和typescript-plugin-css-modules
目录 1,前言 2,效果图 3,如何使用 3.1,安装 3.2,配置 4,示例 5,插件错误处理 5.1,错误触发原因 5.2,解决办法 1,前言 在vite/webpack搭建的项目中,不管是vue ...