当前位置:网站首页>【集训DAY5】选数字【数学】
【集训DAY5】选数字【数学】
2022-08-09 22:35:00 【VL——MOESR】
思路:
预处理出&i==ai的所有数,然后容斥判断就行了
c o d e code code
#include<iostream>
#include<cstdio>
using namespace std;
const int MAXN = 1e5 + 10;
int n, q;
int sum[MAXN][256], a[MAXN], p[256];
long long jisuan(long long x) {
return (x * (x - 1) * (x - 2) / 6);
}
int main() {
p[0] = 0, p[1] = 1, p[2] = 1;
for(int i = 3; i <= 255; i ++) p[i] = p[i / 2] + (i & 1);
scanf("%d%d", &n, &q);
for(int i = 1; i <= n; i ++) scanf("%d", &a[i]);
for(int i = 1; i <= n; i ++)
for(int j = 0; j <= 255; j ++) {
sum[i][j] = sum[i - 1][j] + ((a[i] & j) == a[i]);
}
while(q --) {
int l, r, x;
long long ans = 0;
scanf("%d%d%d", &l, &r, &x);
for(int i = 0; i <= 255; i ++) {
if((i & x) != i) continue;
int g = p[x] - p[i];
if(g & 1) ans -= jisuan(sum[r][i] - sum[l - 1][i]);
else ans += jisuan(sum[r][i] - sum[l - 1][i]);
}
printf("%lld\n", ans);
ans = 0;
}
return 0;
}
边栏推荐
猜你喜欢
随机推荐
Gartner全球集成系统市场数据追踪,超融合市场增速第一
关于服务治理
力扣:474.一和零
用哈希简单封装unordered_map和unordered_set
多线程是同时执行多个线程的吗
深圳堡垒机厂家有哪些?重点推荐哪家?
如何正则匹配乱码?
技术盛宴!华云数据携六大议题亮相OpenInfra Days China
linux上使用docker安装redis
干货!迈向鲁棒的测试时间适应
【Burning】It's time to show your true strength!Understand the technical highlights of the 2022 Huawei Developer Competition in one article
深入理解多线程(第一篇)
torch.distributed多卡/多GPU/分布式DPP(二)——torch.distributed.all_reduce(reduce_mean)&barrier&控制进程执行顺序&随机数种子
【诗歌】最高级的惩罚就是沉默
【哲理】读书的意义
力扣:322. 零钱兑换
全球不用交税的国家,为什么不交
Filament-Material 绘制基本图形
setter与getter访问器属性——数据驱动显示
【诗歌】枕上诗书