题解:CF1899D Yarik and Musical Notes
lailai0916 · · 题解
题意简述
求数列
解题思路
作出
不难发现只有
统计每个元素
因此总方案数为:
参考代码
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
map<int,ll> m;
for(int i=1;i<=n;i++)
{
int t;
cin>>t;
m[t]++;
}
ll ans=m[1]*m[2];
for(auto [x,y]:m)ans+=y*(y-1)/2;
cout<<ans<<'\n';
}
return 0;
}