存个树状数组的板子省的每次都抄别人 struct sgt{ ll c1[N],c2[N]; inline void update(ll x,ll k) { ll i=x; while(x<=n) { c1[x]+=k; c2[x]+=i*k; x+=x&-x; } return; } inline ...
转载
2021-07-16 01:25:00
148阅读
2评论
树状数组[区间修改,区间查询]
原创
2021-12-28 16:25:52
537阅读
今天看了一下树状数组,个人认为树状数组是一个很优美的数据结构,虽然看的并不是很懂。。。一些简单的知识就不讲的,请自行百度。。不过还是讲一些最基础的吧。
概述
树状数组(binary indexed tree),是一种设计新颖的数组结构,它能够高效地获取数组中连续n个数的和。概括说,树状数组通常用于解决以下问题:数组{a}中的元素可能不断地被修改,怎样才能快速地获取一个区间的和?
树状数组基本...
原创
2021-07-14 11:12:33
478阅读
今天看了一下树状数组,个人认为树状数组是一个很优美的数据结构,虽然看的并不是很懂。。。一些简单的知识就不讲的,请自行百度。。不过还是讲一些最基础的吧。概述树状数组(binary indexed tree),是一种设计新颖的数组结构,它能够高效地获取数组中连续n个数的和。概括说,树状数组通常用于解决以下问题:数组{a}中的元素可能不断地被修改,怎样才能快速地获取一个区间的和?树状数组基本...
原创
2022-02-03 17:08:52
660阅读
给出一个长为n的数列,以及n个操作,操作涉及区间加法,区间求和。 这题的询问变成了区间上的询问,不完整的块还是暴力;而要想快速统计完整块的答案,需要维护每个块的元素和,先要预处理一下。 考虑区间修改操作,不完整的块直接改,顺便更新块的元素和;完整的块类似之前标记的做法,直接根据块的元素和所加的值计算
原创
2021-06-05 10:34:59
182阅读
一、内容题意:给定一个序列1—N,给定几组区间,每个区间进行涂色,问最后每个点被涂了几次。二、思路差分数组这里使用线段树lazy标记。查询的时候查询到每个单点。三、代码#include <cstdio>#include <cstring>typedef long long ll;const int maxn = 1e5 + 5;int n, x, y...
原创
2021-08-27 14:21:27
90阅读
一、内容
题意:给定一个序列1—N,给定几组区间,每个区间进行涂色,问最后每个点被涂了几次。
二、思路
差分数组
这里使用线段树lazy标记。查询的时候查询到每个单点。
三、代码
#include <cstdio>
#include <cstring>
typedef long long ll;
const int maxn = 1e5 + 5;
int n, x, y...
原创
2022-02-03 10:59:46
34阅读
题意:一个序列初始都是1,然后操作x y a把区间[x,y]改为a,m次操作后问序列总值。 题解:线段树区间修改水题。#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 100005;int n, m, sum[N << 2], addv[N << 2], l1,
原创
2023-06-29 00:00:33
25阅读
这两题我都在之前做过,但并未通过,那次做的时候是刚开始接触线段树,现在有了一点点的了解,翻出以前
原创
2022-07-18 14:05:53
74阅读
逆十字巨巨的代码 保存一下 #include<bits/stdc++.h> using namespace std; vector<int> v1[300010],v2[300010];//两张图 int T,n,x,y,dep[300010],rt[300010],tot,L[300010],R[ ...
转载
2021-08-09 09:53:00
126阅读
2评论
codevs 1082 白书上很详尽。维护两个东西,一个是差量,也就是哪一段被更新了多少,还有一个也是差量,只不过是记录一共减了多少。(说不清) 然后根据白书上的式子,自己yy一下。还是不是很懂
转载
2016-12-21 23:32:00
66阅读
2评论
这里给一个区间修改,求区间和的代码,也可以用到求区间最值,乘积等问题。 这个想法是sum[]和lazy[]同时修改。以前我写的是lazy[now]往下传给now << 1和now << 1 | 1的时候再修改sum[],这个写法的逻辑不是很好,推荐下面的这个思路。 1 #include<cstdio
原创
2021-05-29 18:45:45
234阅读
链接 给你一个数组 nums ,请你完成两类查询,其中一类查询要求更新数组下标对应的值,另一类查询要求返回数组中某个范围内元素的总和。 实现 NumArray 类: NumArray(int[] nums) 用整数数组 nums 初始化对象 void update(int index, int va ...
转载
2021-10-14 23:15:00
41阅读
2评论
题意 解析 代码 #include<bits/stdc++.h> using namespace std; #define ll long long const int INF = 0x3f3f3f3f,N = 1e6+10; ll c[2][N]; int n,q; int tmp; void u ...
转载
2021-07-26 10:36:00
144阅读
2评论
题意: n个数,有两种操作,一种是查询区间和,另一种是在区间上每一个数加上v。 把bake爷的指针版改造成了结构体版。。 #include#include#include#include#includeusing namespace std;#define ll long long#define N 100105#define inf 100
原创
2021-08-13 13:57:58
93阅读
一、内容World is getting more evil and it's getting tougher to get into the Evil League of Evil. Since the legendary Bad Horse has retired, now you have to correctly answer the evil questions of Dr. Horr...
原创
2021-08-27 14:31:07
75阅读
一、内容World is getting more evil and it's getting tougher to get into the Evil League of Evil. Since the legendary Bad Horse has retired, now you have to correctly answer the evil questions of Dr. Horr...
原创
2022-01-06 17:06:20
32阅读
题意 解析 代码 #include<bits/stdc++.h> using namespace std; #define ll long long const int INF = 0x3f3f3f3f,N = 1e6+10; ll c[2][N]; int n,q; int tmp; void u ...
转载
2021-07-26 10:36:00
124阅读
2评论
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<string.h> 5 using namespace std; 6 typedef long long ll; 7 const ll maxn=1e5+
转载
2019-09-11 22:25:00
109阅读
(一)线段树 1.E - Lost Cows N (2 <= N <= 8,000) cows have uniq
原创
2022-09-23 18:23:35
249阅读