根号分治
笑死,瞪着大眼 5 分钟才看见
本题考虑根号分治,小于
废话不多说,直接看代码:
// Problem: T412755 [LMXOI Round 1] Size
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/T412755?contestId=152140
// Memory Limit: 512 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
//#include <bits/extc++.h>
#define int long long
#define min(x,y) (((x)<(y))?(x):(y))
#define max(x,y) (((x)>(y))?(x):(y))
#define lowbit(x) ((x)&-(x))
#define abs(x) (((x)<(0))?(-(x)):(x))
using namespace std;
//using namespace __gnu_cxx;
//using namespace __gnu_pbds;
int quikpower(int a, int b)
{
// if (b < 0)
// {
// return quikpower(a, b + mod - 1);
// }
int c = 1;
while (b)
{
if (b & 1)
{
c *= a;
// c %= mod;
}
a *= a;
// a %= mod;
b >>= 1;
}
return c;
}
int countbit(int x)
{
// cout << x << "\n";
int ans = 0;
while (x)
{
ans += (x & 1);
x >>= 1;
}
return ans;
}
int n, x, box[10005], ans;
map<int,int> st;
signed main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> x;
if (x <= 10000)
{
box[x]++;
}
else
{
st[x]++;
}
}
for (int i = 1; i <= 1000; i++)
{
for (pair<int,int> j : st)
{
ans += countbit(i + j.first) * box[i] * j.second + countbit(abs(i - j.first)) * box[i] * j.second;
}
}
ans *= 2;
for (int i = 0; i <= 10000; i++)
{
for (int j = 0; j <= 10000; j++)
{
ans += countbit(i + j) * box[i] * box[j] + countbit(abs(i - j)) * box[i] * box[j];
}
}
for (pair<int,int> i : st)
{
for (pair<int,int> j : st)
{
ans += countbit(i.first + j.first) * i.second * j.second + countbit(abs(i.first - j.first)) * i.second * j.second;
}
}
cout << ans;
return 0;
}
提交之后,你会发现全 T 了,我也不知道为啥,但是将分治边界改为