关注
//#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
相关推荐
点赞 评论 收藏
分享
02-02 19:45
厦门理工学院 Java 点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 牛客新年AI问运 #
8645次浏览 116人参与
# 你喜欢工作还是上学 #
89576次浏览 884人参与
# 牛客AI体验站 #
16736次浏览 292人参与
# 被AI治愈的瞬间 #
90774次浏览 686人参与
# 你找工作的时候用AI吗? #
173457次浏览 889人参与
# 有必要和同事成为好朋友吗? #
1383次浏览 27人参与
# 如何提高实习转正率? #
87178次浏览 510人参与
# 听劝,这个公司值得去吗 #
665751次浏览 1996人参与
# 你觉得什么岗位会被AI替代 #
41338次浏览 278人参与
# 为了秋招你都做了哪些准备? #
32647次浏览 534人参与
# 机械人的薪资开到多少,才适合去? #
165205次浏览 573人参与
# 你最满意的offer薪资是哪家公司? #
71563次浏览 355人参与
# 这个工作能去吗 #
115342次浏览 663人参与
# 多益网络工作体验 #
63357次浏览 306人参与
# 工作中的卑微时刻 #
33588次浏览 199人参与
# 秋招吐槽大会 #
304884次浏览 1524人参与
# 央国企投递记录 #
177111次浏览 1655人参与
# 国央企求职进展汇总 #
442854次浏览 3509人参与
# 数字马力求职进展汇总 #
331831次浏览 2381人参与
# 你已经投递多少份简历了 #
1353344次浏览 10821人参与
