可恶,被longlong的长度卡住了,要是longlong再大一点就好了(bushi),其实是算法有问题,里面涉及1e9*1e9*1e9,longlong肯定存不下,一会儿去改改,先记录一下。
题目:竞赛 - AcWing
输入样例1:
4
1 1 1 1
输出样例1:
4
输入样例2:
5
1 3 2 3 4
输出样例2:
2
输入样例3:
6
1 3 3 1 3 2
输出样例3:
1
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5+10;
int n,m;
map<LL,LL> mpl,mpr;
LL a[N];
LL sum = 0;
LL Max = 1e9;
int main()
{
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
if(i)mpr[a[i]]++;
else mpl[a[i]]++;
}
//map<int, int>::iterator it = mp.begin()
for(int i=1;i<n-1;i++){
mpr[a[i]]--;
if(mpr[a[i]] == 0)mpr.erase(a[i]);
//计算乘积
//取出左边最小值的值和右边最小值的值
map<LL, LL>::iterator itl = mpl.begin();
map<LL, LL>::iterator itr = mpr.begin();
LL l = itl->first;
LL r = itr->first;
LL C = l * r * a[i];
//如果乘积比当前Max小,更新Max和sum,大则忽略,相等就给sum加
if(C < Max){
Max = C;
sum = itl->second * itr->second;
}else if(C == Max){
sum += itl->second * itr->second;
}
//右边最小值个数--,如果为0则删除,左边a[i]++
mpl[a[i]]++;
}
cout<<sum;
return 0;
}