B. Makes And The Product
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

After returning from the army Makes received a gift — an array a consisting of n positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (i,  j,  k) (i < j < k), such that ai·aj·akis minimum possible, are there in the array? Help him with it!

Input

The first line of input contains a positive integer number n (3 ≤ n ≤ 105) — the number of elements in array a. The second line contains npositive integer numbers ai (1 ≤ ai ≤ 109) — the elements of a given array.

Output

Print one number — the quantity of triples (i,  j,  k) such that i,  j and k are pairwise distinct and ai·aj·ak is minimum possible.

Examples
input

Copy
4
1 1 1 1
output

Copy
4
input

Copy
5
1 3 2 3 4
output

Copy
2
input

Copy
6
1 3 3 1 3 2
output

Copy
1
Note

In the first example Makes always chooses three ones out of four, and the number of ways to choose them is 4.

In the second example a triple of numbers (1, 2, 3) is chosen (numbers, not indices). Since there are two ways to choose an element 3, then the answer is 2.

In the third example a triple of numbers (1, 1, 2) is chosen, and there's only one way to choose indices.

思路:

分三种情况来逐一考虑,

a[1]=a[2]=a[3]

a[1],a[2]=a[3]

a[1],a[2],a[3]

根据题目要求的约数,只可能为这三种情况,

分类处理下就OK

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
map<ll,ll> m;
ll n;
ll a[maxn];
ll getpc(ll m,ll n)//m 中 选 n 个
{
long long ans=;
for(long long k=; k<=n; k++)
{
ans=(ans*(m-n+k))/k;
}
return ans;
}
int main()
{
gbtb;
cin>>n;
repd(i,,n)
{
cin>>a[i];
m[a[i]]=m[a[i]]+;
}
sort(a+,a++n);
ll ans=0ll;
set<ll> s;
repd(i,,)
{
s.insert(a[i]);
}
// 1 1 1 1 1 if(s.size()==)
{
ll sum=m[a[]];
// c 4 3
ans=getpc(sum,); }else if(s.size()==)
{
// 1 1 2 2 2 2 3
// 1 2 2 2 2 2
ll f=m[a[]];
if(f==)
{
ans=getpc(m[a[]],);
}else
{
ans=m[a[]];
}
}else
{
// 1 2 3 3 3 3
ans=m[a[]];
}
// cout<
cout<<ans<<endl;
return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}

Makes And The Product CodeForces - 817B (思维+构造)的更多相关文章

  1. A Mist of Florescence CodeForces - 989C(思维构造)

    题意: 让你构造一个图,使得A,B,C,D的个数为给定的个数,上下左右连通的算一个. 哎呀 看看代码就懂了..emm..很好懂的 #include <bits/stdc++.h> usin ...

  2. hdu4671 思维构造

    pid=4671">http://acm.hdu.edu.cn/showproblem.php? pid=4671 Problem Description Makomuno has N ...

  3. codeforces 1041 e 构造

    Codeforces 1041 E 构造题. 给出一种操作,对于一棵树,去掉它的一条边.那么这颗树被分成两个部分,两个部分的分别的最大值就是这次操作的答案. 现在给出一棵树所有操作的结果,问能不能构造 ...

  4. 思维/构造 HDOJ 5353 Average

    题目传送门 /* 思维/构造:赛后补的,当时觉得3题可以交差了,没想到这题也是可以做的.一看到这题就想到了UVA_11300(求最小交换数) 这题是简化版,只要判断行不行和行的方案就可以了,做法是枚举 ...

  5. Prefix Product Sequence CodeForces - 487C (数论,构造)

    大意: 构造一个[1,2,...n]的排列, 使得前缀积模n为[0,1,...,n-1]的排列 这种构造都好巧妙啊, 大概翻一下官方题解好了 对于所有>=6的合数$n$, 有$(n-1)! \e ...

  6. Educational Codeforces Round 53C(二分,思维|构造)

    #include<bits/stdc++.h>using namespace std;const int N=1e6+6;int x[N],y[N];int sx,sy,n;char s[ ...

  7. Codeforces 232A - Cycles (构造 + 思维)

    题目链接: 232A - Cycles(点击打开) 题意: 要构成一个存在 \(k\) 个三元环的图,需要多少个点,输出顶点数 \(n\),并输出图. 题解: 题目中的任何图都可以用 \(90\)~ ...

  8. Vasya And The Matrix CodeForces - 1016D (思维+构造)

    Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the ma ...

  9. CF1103C Johnny Solving (Codeforces Round #534 (Div. 1)) 思维+构造

    题目传送门 https://codeforces.com/contest/1103/problem/C 题解 这个题还算一个有难度的不错的题目吧. 题目给出了两种回答方式: 找出一条长度 \(\geq ...

随机推荐

  1. Javascript 高级程序设计--总结【四】

    *******************************  Chapter 11 DOM扩展  ******************************* 主要的扩展是 选择符API 和 H ...

  2. Hive中笔记 :三种去重方法,distinct,group by与ROW_Number()窗口函数

    一.distinct,group by与ROW_Number()窗口函数使用方法 1. Distinct用法:对select 后面所有字段去重,并不能只对一列去重. (1)当distinct应用到多个 ...

  3. 将DataTable中的数据一次性提交到数据库中

    实现功能的核心代码 SqlConnection destinationConnection = new SqlConnection(connectionString);destinationConne ...

  4. Apache中httpd.conf文件的详解

    PHP中,Apache的配置至关重要,特别是httpd.conf这个文件,它是Apache中的核心文件.好了,废话不说,今天将这个文件中的一些内容讲解一番. ServerRoot "d:/w ...

  5. windows7家庭版,专业版,旗舰版,企业版版本区别

    Windows 7包含6个版本,分别为Windows 7 Starter(初级版).Windows 7 Home Basic(家庭普通版).Windows 7 Home Premium(家庭高级版). ...

  6. ASP.NET -- WebForm -- 页面生命周期

    ASP.NET -- WebForm --  页面生命周期 ASP.NET 页运行时,此页将经历一个生命周期,在生命周期中将执行一系列处理步骤.这些步骤包括初始化.实例化控件.还原和维护状态.运行事件 ...

  7. Java多线程 Socket使用

    点我跳过黑哥的卑鄙广告行为,进入正文. Java多线程系列更新中~ 正式篇: Java多线程(一) 什么是线程 Java多线程(二)关于多线程的CPU密集型和IO密集型这件事 Java多线程(三)如何 ...

  8. 05.Python网络爬虫之三种数据解析方式

    引入 回顾requests实现数据爬取的流程 指定url 基于requests模块发起请求 获取响应对象中的数据 进行持久化存储 其实,在上述流程中还需要较为重要的一步,就是在持久化存储之前需要进行指 ...

  9. ES5-ES6-ES7_解构赋值

    解构赋值的概念 ES6允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构(Destructuring) 传统对变量赋值的方式,以前,为变量赋值,只能直接指定值. var a = 1; ...

  10. 网络协议 反扒机制 fidder 抓包工具

    协议 http 协议: client 端 server 端交互的 一种形式 请求头信息: User-Agent: 情求载体的身份标识 connection: 'close' 连接状态 请求成功后 断开 ...