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的更多相关文章

  1. [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 ...

  2. [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 ...

  3. [LeetCode] Distinct Subsequences 不同的子序列

    Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...

  4. SQL中distinct的用法

    SQL中distinct的用法   1.作用于单列 2.作用于多列 3.COUNT统计 4.distinct必须放在开头 5.其他 在表中,可能会包含重复值.这并不成问题,不过,有时您也许希望仅仅列出 ...

  5. Oracle 查询语句(where,order by ,like,in,distinct)

    select * from production;alter table production add productionprice number(7,2); UPDATE production s ...

  6. mysql中distinct的用法

    本事例实验用表task,结构如下 MySQL> desc task; +-------------+------------+------+-----+-------------------+- ...

  7. Distinct Subsequences

    https://leetcode.com/problems/distinct-subsequences/ Given a string S and a string T, count the numb ...

  8. distinct 与 group by 去重

    例如下表格:表名:fruit id Name Price Num 1 西瓜 10 2 2 西瓜 11 2 3 香蕉 10 3 4 桃子 10 2 当我想获取Name不重复的数据,结果如下 id Nam ...

  9. 大数据下的Distinct Count(二):Bitmap篇

    在前一篇中介绍了使用API做Distinct Count,但是精确计算的API都较慢,那有没有能更快的优化解决方案呢? 1. Bitmap介绍 <编程珠玑>上是这样介绍bitmap的: B ...

随机推荐

  1. 微信access_token缓存与更新

    由于Access Token有效期只有7200秒,而每天调用获取的次数只有2000次,所以需要将Access Token进行缓存来保证不触发超过最大调用次数.另外在微信公众平台中,绝大多数高级接口都需 ...

  2. 【Redis】ziplist压缩列表

    压缩列表 压缩列表是列表和哈希表的底层实现之一: 如果一个列表只有少量数据,并且数据类型是整数或者比较短的字符串,redis底层就会使用压缩列表实现. 如果一个哈希表只有少量键值对,并且每个键值对的键 ...

  3. go统计字符串及数组中出现次数

    数组:统计出现字数 package main import "fmt" func main() { s := [...]string{"Mlxg", " ...

  4. 梯度下降GD,随机梯度下降SGD,小批量梯度下降MBGD

    阅读过程中的其他解释: Batch和miniBatch:(广义)离线和在线的不同

  5. .NET Core 实现后台任务(定时任务)Longbow.Tasks 组件(三)

    原文链接:https://www.cnblogs.com/ysmc/p/16512309.html 在上两篇文章中,简单介绍了怎么使用 IHostedService 与 BackgroundServi ...

  6. Running Median_via牛客网

    题目 链接:https://ac.nowcoder.com/acm/contest/28886/1002 来源:牛客网 时间限制:C/C++ 5秒,其他语言10秒 空间限制:C/C++ 65536K, ...

  7. npm、cnpm与package-lock.json的操作

    来源:npm.cnpm与package-lock.json的操作_IT码农-爱吃辣条的博客-CSDN博客_cnpm lock package.json文件只能锁定大版本,也就是版本号的第一位,并不能锁 ...

  8. 来看看这位年轻的 eBay 小伙是如何成为 Committer

    介绍一下我自己 目前就职于eBay中国,专注于微服务中间件,分布式架构等领域,同时也是狂热的开源爱好者. 如何成为一个commiter 过去几个月,我一直持续在为 Apache DolphinSche ...

  9. Java集合容器的深度理解

    Java容器里有很多写好的容器API,这使我们很方便的可以存储.操作我们的数据. 下面是我写的容器的特点,一些容器的不同之处,从底层源码解析一下容器实现原理 一.常用的容器目录 上图可以看出,java ...

  10. BZOJ3037 创世纪(基环树DP)

    基环树DP,攻的当受的儿子,f表选,g表不选.并查集维护攻受关系.若有环则记录,DP受的后把它当祖宗,再DP攻的. #include <cstdio> #include <iostr ...