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. 【Redis】字典

    Redis 字典 基本语法 字典是Redis中的一种数据结构,底层使用哈希表实现,一个哈希表中可以存储多个键值对,它的语法如下,其中KEY为键,field和value为值(也是一个键值对): HSET ...

  2. vivo 容器集群监控系统架构与实践

    vivo 互联网服务器团队-YuanPeng 一.概述 从容器技术的推广以及 Kubernetes成为容器调度管理领域的事实标准开始,云原生的理念和技术架构体系逐渐在生产环境中得到了越来越广泛的应用实 ...

  3. BUUCTF-镜子里的世界

    镜子里面的世界 16进制看了下没有东西,binwalk分离了一下也没发现其他的,使用stegsolve查看即可发现.

  4. Windows-VS2017创建.NET项目

    首先新建->项目 选择如下, 注意要选择.NET Framework4.x 选择对应的项目类型 建议选上Web窗体(如果是用于实验的话) 完成后进行测试 如果出现 HTTP Error 403. ...

  5. sql-DCL用户及权限管理及其他常用命令-oracle

    DCL 用户管理 创建用户 create user 用户名 identified by 密码; 在oracle中要创建一个新的用户使用create user语句,一般是具有dba(数据库管理员)的权限 ...

  6. python小题目练习(九)

    题目:将美元转化为人民币 需求:实现如图所示需求  代码展示: """Author:mllContent:将美元转化为人民币Date:2020-11-23"&q ...

  7. 令你瞠目结舌的 Python 代码技巧

    0. for-else 在 Python 中,else 不仅可以与 if 搭配使用,还可以与 for 结合. python答疑 咨询 学习交流群2:660193417### for x in rang ...

  8. python基础教程:定义类创建实例

    类的定义 在Python中,类通过class关键字定义,类名以大写字母开头 >>>class Person(object): #所有的类都是从object类继承 pass #pass ...

  9. 10分钟实现dotnet程序在linux下的自动部署

    背景 一直以来,程序署都是非常麻烦且无聊的事情,在公司一般都会有 devops 方案,整个 cicd 过程涉及的工具还是挺多的,搭建起来比较麻烦.那么对于一些自己的小型项目,又不想搭建一套这样的环境, ...

  10. C语言求100以内的和的4种方式

    C语言的一个很经典的例子,帮助熟练运行几个循环的写法 * 方法一(do---while语句) #include main () { int i,sum=0; do { sum=sum+i; i++; ...