关注
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
using namespace std;
#define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
typedef long long LL;
void fwtXor(LL* a, int len) {
if(len == 1) return;
int h = len >> 1;
fwtXor(a, h);
fwtXor(a + h, h);
for(int i = 0; i < h; ++i) {
LL x1 = a[i];
LL x2 = a[i + h];
a[i] = (x1 + x2);
a[i + h] = (x1 - x2);
}
}
void ifwtXor(LL* a, int len) {
if(len == 1) return;
int h = len >> 1;
for(int i = 0; i < h; ++i) {
// y1=x1+x2
// y2=x1-x2
LL y1 = a[i];
LL y2 = a[i + h];
a[i] = (y1 + y2) / 2;
a[i + h] = (y1 - y2) / 2;
}
ifwtXor(a, h);
ifwtXor(a + h, h);
}
LL n, m;
const int C = 1 << 17;
LL cnt[C];
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> m;
for(int i = 1; i <= n; ++i) {
int x; cin >> x;
++cnt[x];
}
fwtXor(cnt, C);
for(int i = 0; i < C; ++i) cnt[i] *= cnt[i];
ifwtXor(cnt, C);
cnt[0] -= n;
for(int i = 0; i < C; ++i) cnt[i] >>= 1;
LL ans = 0;
for(int i = m + 1; i < C; ++i) ans += cnt[i];
cout << ans << endl;
return 0;
}
用FWT过了,这题应该是需要字典树做。
查看原帖
点赞 2
相关推荐
11-16 00:38
重庆师范大学 咨询项目管理 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 那些年,我收到的‘奇葩’回复 #
10150次浏览 102人参与
# 小马智行求职进展汇总 #
16261次浏览 54人参与
# 腾讯音乐秋招 #
426508次浏览 4757人参与
# OC/开奖 #
170231次浏览 1252人参与
# 秋招你经历过哪些无语的事 #
11342次浏览 141人参与
# 职场中那些令人叹为观止的八卦 #
20693次浏览 194人参与
# 百度秋招 #
47673次浏览 373人参与
# 校招薪资来揭秘 #
43401次浏览 311人参与
# 秋招吐槽大会 #
66372次浏览 592人参与
# 你找工作想离家近 or 离家远? #
12622次浏览 207人参与
# 如果校招重来我最想改变的是 #
335401次浏览 3141人参与
# 租房前辈的忠告 #
283014次浏览 7246人参与
# 多益网络求职进展汇总 #
50954次浏览 241人参与
# 我的职场社死时刻 #
15274次浏览 135人参与
# 哪些公司开始补录了 #
15745次浏览 143人参与
# 一人推荐一个值得去的通信/硬件公司 #
223443次浏览 2054人参与
# 你秋招最后悔的选择 #
12060次浏览 90人参与
# XX请雇我工作 #
11042次浏览 89人参与
# 秋招提前批,你开始投了吗 #
678757次浏览 8395人参与
# 满帮集团求职进展汇总 #
11569次浏览 89人参与
# 毕业租房也有小确幸 #
144621次浏览 4505人参与
# 你父母给过你哪些不靠谱的职场建议? #
11519次浏览 165人参与