关注
//#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
相关推荐
点赞 评论 收藏
分享
06-03 12:21
江西师范大学 C++ 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 实习,不懂就问 #
5337次浏览 76人参与
# 小米提前批笔试难吗 #
34195次浏览 358人参与
# 现代汽车前瞻技术研发急速编程挑战赛 #
14869次浏览 146人参与
# 26届校招投递进展 #
32640次浏览 248人参与
# 央国企投递记录 #
88319次浏览 1362人参与
# 为了找工作你花了哪些钱? #
28672次浏览 275人参与
# 神州信息工作体验 #
11716次浏览 57人参与
# 校招第一份工作你干了多久? #
86339次浏览 399人参与
# 来聊聊你目前的求职进展 #
634485次浏览 6747人参与
# 考公还是考研,你怎么选? #
27859次浏览 140人参与
# 小米硬件提前批进度交流 #
168243次浏览 1523人参与
# 外包能不能当跳板? #
34609次浏览 221人参与
# 你觉得专业和学校哪个对薪资影响最大 #
61455次浏览 491人参与
# 设计人的面试记录 #
123644次浏览 1341人参与
# 打工人的精神状态 #
50057次浏览 867人参与
# 硬件人你反向读研了吗 #
42587次浏览 637人参与
# 如果中了500万,你会离职吗? #
84616次浏览 654人参与
# 你今年的保底offer是哪家 #
118583次浏览 538人参与
# 大疆的机械笔试比去年难吗 #
72999次浏览 619人参与
# 怎么评价今年的华为 #
129170次浏览 568人参与
# 硬件人秋招的第一个offer #
78050次浏览 1149人参与