Codeforces 769D k-Интересные пары чисел

时间:2023-03-09 19:03:41
Codeforces 769D k-Интересные пары чисел

题目链接:http://codeforces.com/contest/769/problem/D


搜索题

考虑这些数的值域较小,直接${O(2^{k})}$次方枚举每个数字二进制位上是否改变,剪枝一下最不利复杂度为${O(C_{14}^{7})}$,有${10^{4}}$中取值。

最终最不利复杂度为${O(C_{14}^{7}*(10^{4}))}$


 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 100010
#define llg long long
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,str[maxn],c[maxn],k,v[maxn];
vector<llg>a[maxn];
llg d[maxn];
void ss1(llg wz,llg res,llg x)
{
if (wz==)
{
if (res==)
{
llg val=;
for (llg i=;i<;i++) val+=(<<i)*((str[i]+c[i])%);
a[x].push_back(val);
}
return ;
}
if (res)
{
c[wz]=;
ss1(wz+,res-,x);
}
c[wz]=;
ss1(wz+,res,x);
} void ss2(llg wz,llg res,llg x)
{
if (wz==)
{
if (res==)
{
llg val=;
for (llg i=;i<;i++) val+=(<<i)*((str[i]+c[i])%);
a[x].push_back(val);
}
return ;
}
if (res)
{
c[wz]=;
ss2(wz+,res-,x);
}
c[wz]=;
ss2(wz+,res,x);
} void change_(llg x)
{
llg cs=;
while (cs<)
{
str[cs]=x%;
x/=;
cs++;
}
} int main()
{
yyj("D");
cin>>n>>k;
for (llg i=;i<=;i++)
{
change_(i);
if (k<=) ss1(,k,i);else ss2(,-k,i);
}
for (llg i=;i<=n;i++) scanf("%lld",&v[i]),d[v[i]]++;
llg ans=;
for (llg i=;i<=n;i++)
{
llg w=a[v[i]].size(),x=v[i];
for (llg j=;j<w;j++)
if (k==) ans+=d[a[x][j]]-; else ans+=d[a[x][j]];
}
cout<<ans/;
return ;
}