关注
//#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
相关推荐
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 26届秋招公司红黑榜 #
9354次浏览 31人参与
# 实习必须要去大厂吗? #
145954次浏览 1535人参与
# 智慧芽求职进展汇总 #
16238次浏览 103人参与
# 校招泡的最久的公司是哪家? #
3698次浏览 19人参与
# 度小满求职进展汇总 #
9766次浏览 49人参与
# 帮我看看,领导说这话什么意思? #
4653次浏览 24人参与
# 未岚大陆求职进展汇总 #
23609次浏览 108人参与
# 职场新人体验 #
95289次浏览 642人参与
# 你觉得mentor喜欢什么样的实习生 #
9130次浏览 265人参与
# 没有家庭托举的我是怎么找工作的 #
11404次浏览 156人参与
# 入职第一天,你准备什么时候下班 #
85258次浏览 467人参与
# 从哪些方向判断这个offer值不值得去? #
5968次浏览 90人参与
# 技术岗笔试题求解 #
95262次浏览 1101人参与
# 求职低谷期你是怎么度过的 #
4672次浏览 81人参与
# 最难的技术面是哪家公司? #
54711次浏览 893人参与
# 面试紧张时你会有什么表现? #
1388次浏览 20人参与
# 独居后,你的生活是更好了还是更差了? #
27960次浏览 263人参与
# 机械人的工作环境真的很差吗 #
24792次浏览 119人参与
# 秋招想进国企该如何准备 #
97544次浏览 487人参与
# 你有哪些缓解焦虑的方法? #
37021次浏览 835人参与
# 跳槽时有那些注意事项 #
105973次浏览 567人参与
# 工作压力大怎么缓解 #
117591次浏览 1108人参与