关注
//#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
相关推荐
2025-11-22 20:21
香港科技大学(广州) 产品经理 点赞 评论 收藏
分享
01-13 12:51
电子科技大学 算法工程师 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 你最近因为什么迷茫? #
3737次浏览 80人参与
# 秋招有哪些公司要求提前实习 #
102108次浏览 542人参与
# 领导做过最不靠谱的事 #
2651次浏览 51人参与
# 求职你最看重什么? #
151929次浏览 882人参与
# 你都在哪些场所面过试? #
2430次浏览 39人参与
# 实习转正进行时 #
137952次浏览 892人参与
# 当发现同事想辞职 #
13542次浏览 44人参与
# 工作压力大怎么缓解 #
132317次浏览 1137人参与
# 实习心态崩了 #
99852次浏览 502人参与
# 制造业的秋招小结 #
139310次浏览 2078人参与
# 电网求职进展汇总 #
37174次浏览 112人参与
# 运营商笔面经互助 #
195420次浏览 1804人参与
# 打工人锐评公司红黑榜 #
190934次浏览 1051人参与
# 在找工作求抱抱 #
1639356次浏览 10960人参与
# 担心入职之后被发现很菜怎么办 #
275743次浏览 1176人参与
# 哪些公司对双非友好 #
200697次浏览 1150人参与
# 面试被问期望薪资时该如何回答 #
338430次浏览 2104人参与
# 电信求职进展汇总 #
38117次浏览 195人参与
# 校招谈薪技巧 #
126398次浏览 1353人参与
# Prompt分享 #
5338次浏览 139人参与
三奇智元机器人科技有限公司公司福利 83人发布