当前位置:网站首页>【集训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;
}
边栏推荐
猜你喜欢
金仓数据库 KingbaseGIS 使用手册(6.4. 几何对象存取函数)
外包的水有多深?腾讯15k的外包测试岗能去吗?
伦敦银行情中短线的支撑和阻力位
Mysql集群 ShardingSphere
了解什么是架构基本概念和架构本质
2022-08-09 mysql/stonedb-subquery performance improvement-introduction
k8s部署mysql
2020年度SaaS TOP100企业名单
Interfering with BGP routing---community attributes
Technology feast!Huayun Data brings six topics to OpenInfra Days China
随机推荐
The latest "Grain Academy Development Tutorial" in 2022: 10 - Front-end payment module
深入理解多线程(第一篇)
集合运算样例
直播间搭建,按钮左滑出现删除等操作按钮
&& 不是此版本的有效语句分隔符
高手这样看现货白银走势图
2022年最新《谷粒学院开发教程》:10 - 前台支付模块
了解什么是架构基本概念和架构本质
What are the Shenzhen fortress machine manufacturers?Which one do you recommend?
力扣:322. 零钱兑换
直播平台怎么搭建,原生js实现编辑器撤消/恢复功能
harbor配置远程仓库
SRv6性能测量
Has your phone ever been monitored?
【诗歌】最高级的惩罚就是沉默
Leetcode 236. 二叉树的最近公共祖先
【励志】名言警句
Cmake 用法记录
金仓数据库 KingbaseGIS 使用手册(6.4. 几何对象存取函数)
集群的基础形式