QUERIES
这个题解。。
u1s1我没看懂,但是我觉得这里面有一个重要的思想就是对于像异或这种最终值只是看一个数位的问题,我们可以考虑分解,把每一个子问题单独解决就可以了
其实更难的应该是每个子区间的异或和之和这个方面。。
这里放上dalao的代码
#include<bits/stdc++.h>
using namespace std;
const int N = 100009, M = 400009, Mod = 4001;
int n, m, a[N];
struct tree{int l0, l1, r0, r1, sum, val0, val1;} t[M][11];
tree merge(tree x, tree y) {
tree tmp = {};
tmp.val0 = x.val0 + y.val0 + x.r0 * y.l0 % Mod + x.r1 * y.l1 % Mod;
tmp.val1 = x.val1 + y.val1 + x.r0 * y.l1 % Mod + x.r1 * y.l0 % Mod;
if (x.sum == 0) tmp.l0 = x.l0 + y.l0, tmp.l1 = x.l1 + y.l1;
else tmp.l0 = x.l0 + y.l1, tmp.l1 = x.l1 + y.l0;
if (y.sum == 0) tmp.r0 = y.r0 + x.r0, tmp.r1 = y.r1 + x.r1;
else tmp.r0 = y.r0 + x.r1, tmp.r1 = y.r1 + x.r0;
tmp.val0 %= Mod, tmp.val1 %= Mod, tmp.l0 %= Mod, tmp.l1 %= Mod, tmp.r0 %=
Mod, tmp.r1 %= Mod, tmp.sum = x.sum ^ y.sum;
return tmp;
}
void change(int p, int l, int r, int k, int u, int v) {
if (l > u || r < u) return ;
if (l == r && l == u) {
if (v == 0) t[p][k].l0 = t[p][k].r0 = t[p][k].val0 = 1, t[p][k].l1 =
t[p][k].r1 = t[p][k].val1 = 0;
else t[p][k].l0 = t[p][k].r0 = t[p][k].val0 = 0, t[p][k].l1 = t[p][k].r1
= t[p][k].val1 = 1;
t[p][k].sum = v;
return ;
}
int mid = l + r >> 1;
change(p << 1, l, mid, k, u, v);
change(p << 1 | 1, mid + 1, r, k, u, v);
t[p][k] = merge(t[p << 1][k], t[p << 1 | 1][k]);
}
tree ask(int p, int l, int r, int k, int x, int y) {
if (y < l || x > r) return t[0][0];
if (x <= l && r <= y) return t[p][k];
int mid = l + r >> 1; return merge(ask(p << 1, l, mid, k, x, y), ask(p << 1 | 1, mid + 1, r, k, x,
y));
}
int power(int a, int b) {int res = 1; for (; b; b >>= 1, a = 1LL * a * a % Mod)
if (b & 1) res = 1LL * res * a % Mod; return res;}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++ i) {
int x;
scanf("%d", &x);
for (int j = 1; j <= 10; ++ j) change(1, 1, n, j, i, x & (1 << j - 1));
}
while(m --) {
int op, x, y;
scanf("%d%d%d", &op, &x, &y);
if (op == 1) for (int i = 1; i <= 10; ++ i) change(1, 1, n, i, x, y & (1
<< i - 1));
else {
int res = 0;
for (int i = 1; i <= 10; ++ i) res = (res + 1LL * ask(1, 1, n, i, x,
y).val1 * power(2, i - 1) % Mod) % Mod;
printf("%d\n", res);
}
}
return 0;
}
QUERIES的更多相关文章
- 实践 HTML5 的 CSS3 Media Queries
先来介绍下 media,确切的说应该是 CSS media queries(CSS 媒体查询),媒体查询包含了一个媒体类型和至少一个使用如宽度.高度和颜色等媒体属性来限制样式表范围的表达式.CSS3 ...
- SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问
delphi ado 跨数据库访问 语句如下 ' and db = '帐套1' 报错内容是:SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATE ...
- CSS3 Media Queries 实现响应式设计
在 CSS2 中,你可以为不同的媒介设备(如屏幕.打印机)指定专用的样式表,而现在借助 CSS3 的 Media Queries 特性,可以更为有效的实现这个功能.你可以为媒介类型添加某些条件,检测设 ...
- 使用CSS3 Media Queries实现网页自适应
原文来源:http://webdesignerwall.com 翻译:http://xinyo.org 当今银屏分辨率从 320px (iPhone)到 2560px (大屏显示器)或者更大.人们也不 ...
- SQL Queries from Transactional Plugin Pipeline
Sometimes the LINQ, Query Expressions or Fetch just doesn't give you the ability to quickly query yo ...
- Media Queries 详解
Media Queries直译过来就是“媒体查询”,在我们平时的Web页面中head部分常看到这样的一段代码: <link href="css/reset.css" rel ...
- SPOJ GSS3 Can you answer these queries III[线段树]
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...
- SPOJ GSS1 Can you answer these queries I[线段树]
Description You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ). A q ...
- 【Codeforces710F】String Set Queries (强制在线)AC自动机 + 二进制分组
F. String Set Queries time limit per test:3 seconds memory limit per test:768 megabytes input:standa ...
- CSS3 媒体查询移动设备尺寸 Media Queries for Standard Devices (包括 苹果手表 apple watch)
/* ----------- iPhone 4 and 4S ----------- */ /* Portrait and Landscape */ @media only screen and (m ...
随机推荐
- Python运维开发之路《函数进阶》
面向对象类的进阶 抽象类 python 没有抽象类.接口的概念,所以要实现这种功能需要导入abc模块 py2:导入abc函数,_metaclass__ = abc.ABCMeta;在强制调用类下:@a ...
- redis集群报错:MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk.
之前在x86架构的服务器部署redis集群,未遇到题中问题:然而在ARM架构的服务器部署redis集群,第一次遇到如此问题.虽然问题已经解决,但不清楚问题的具体原因,在此做个记录. 性能测试过程中,通 ...
- vue3中使用defineExpose报TS-2339
开头先把错误贴上 src/hooks/usePageSearch.ts:9:27 TS2339: Property 'getPageData' does not exist on type '{ $: ...
- java发送http请求(jquery发送http请求,前后端看这一篇文章够了,很完整)
为什么写这篇博客? 1.目前很多系统使用了微服务架构,那么各个微服务之间进行内部通信一般采用http协议的方式,springcloud中提供了ribbon,feign,openFeign等组件. 但是 ...
- 行行AI人才直播第13期:刘红林律师《AIGC创业者4大法律问题需注意》
行行AI人才(海南行行智能科技有限公司)是博客园和顺顺智慧共同运营的AI行业人才全生命周期服务平台. AIGC爆火至今,商业落地已成为各行各业焦点的问题.它的广泛应用也带来了一系列的法律风险和挑战.一 ...
- Linux 使用grep过滤字符串中的指定内容
命令示例:echo port 1234 123 | grep -oP 'port\s+\K\d+' 返回: 1234 这条命令使用 grep 工具来在文本中查找 "Port " 后 ...
- 代码随想录算法训练营第二天| LeetCode 977.有序数组的平方 ,209.长度最小的子数组 ,59.螺旋矩阵II
977.有序数组的平方 题目链接:https://leetcode.cn/problems/squares-of-a-sorted-array/ 文章讲解:https://programmercarl ...
- Echarts: 同时显示柱状图和前端
完整代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- nginx配置gzip压缩
前言 为提高用户获取响应数据的速度,Nginx服务器可以将响应数据进行gzip压缩,在减小响应数据的大小后再发送给用户端浏览器. 要想启用gzip压缩,需要浏览器支持gzip压缩功能,目前大多数浏览器 ...
- 开源.NetCore通用工具库Xmtool使用连载 - HTTP请求篇
[Github源码] <上一篇> 介绍了Xmtool工具库中的XML操作类库,今天我们继续为大家介绍其中的HTTP请求类库. 在现如今的软件需求场景中,HTTP网络请求几乎是开发过程中必然 ...