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. Solon 1.8.3 发布,云原生微服务开发框架

    相对于 Spring Boot 和 Spring Cloud 的项目 启动快 5 - 10 倍 qps 高 2- 3 倍 运行时内存节省 1/3 ~ 1/2 打包可以缩小到 1/2 ~ 1/10(比如 ...

  2. django生成迁移文件和执行迁移的命令

    生成迁移文件: python manage.py makemigrations    #创建数据库迁移文件 执行迁移: python manage.py migrate    # 根据数据库迁移文件生 ...

  3. Python:27行代码实现将多个Excel表格内容批量汇总合并到一个表格

    序言 (https://jq.qq.com/?_wv=1027&k=GmeRhIX0) 老板最近越来越过分了,快下班了发给我几百个表格让我把内容合并到一个表格内去.还好我会Python,分分钟 ...

  4. Python爬虫+数据可视化教学:分析猫咪交易数据

    猫猫这么可爱 不会有人不喜欢吧: 猫猫真的很可爱,和我女朋友一样可爱~你们可以和女朋友一起养一只可爱猫猫女朋友都有的吧?啊没有的话当我没说-咳咳网上的数据太多.太杂,而且我也不知道哪个网站的数据比较好 ...

  5. 拉取服务器上的项目,svn认证失败

    解决方案: 在服务器上找到对应的项目路径,并修改authz: 我的是因为[group]组下(下图中34行),我写的是[demo:/],改为[/]就可以了.

  6. colab解压.tar.gz文件指令

    !tar -zxvf flower_photos.tar.gz 成功后如图:

  7. windows 安全

    Windows基础篇html { overflow-x: initial !important } :root { --bg-color: #ffffff; --text-color: #333333 ...

  8. Python中print()函数的用法详情

    描述 print() 方法用于打印输出,最python中常见的一个函数. 在交互环境中输入help(print)指令,可以显示print()函数的使用方法. >>> help(pri ...

  9. 基于 Hexo 从零开始搭建个人博客(五)

    阅读本篇前,请先阅读前几篇文章: 基于 Hexo 从零开始搭建个人博客(一) 基于 Hexo 从零开始搭建个人博客(二) 基于 Hexo 从零开始搭建个人博客(三) 基于 Hexo 从零开始搭建个人博 ...

  10. 项目配置yaml

    springboot的一些配置 #当循环调用时,就会报错 spring.main.allow-circular-references=true #配置mvc是需要使用一个@EnableWebMvc,不 ...