![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
线段树
2Ululu
这个作者很懒,什么都没留下…
展开
-
LeetCode 370 线段树懒标记板子
线段树维护区间和原创 2022-06-04 23:56:54 · 233 阅读 · 0 评论 -
LeetCode 699 线段树懒标记之动态开点(c++)
class Node {public: Node* left; Node* right; int l; int r; int mid; int v; int add; Node(int l, int r) { this->l = l; this->r = r; this->mid = (l + r) >> 1; this->left = th.原创 2022-05-27 18:06:49 · 275 阅读 · 0 评论 -
LeetCode 1622 线段树懒标记板子题(c++)
using ll=long long;class SegmentTree{public: const static int N=1e5+1,mod=1e9+7; vector<ll> tree,markA,markB; SegmentTree(){ tree.resize(N<<2,0),markA.resize(N<<2,1),markB.resize(N<<2,0); } void update.原创 2022-05-27 16:49:42 · 207 阅读 · 0 评论 -
区间操作的python3板子 LeetCode 715. Range 模块
注意事项:区间都是左闭又开[x,y)from sortedcontainers import SortedListclass RangeModule: def __init__(self): self.rl=SortedList() self.count=0 def addRange(self, left: int, right: int) -> None: #[left,right) right-=1原创 2022-05-16 16:34:19 · 295 阅读 · 0 评论 -
LeetCode1649. 通过指令创建有序数组 C++ 树状数组和线段树
树状数组template <class T> class FenwickTree { int limit; vector<T> arr; //树状数组是从1开始储存的,而不是0 inline int lowbit(int x) { return x & (-x); }public: FenwickTree(int limit=1) { this->limit = limit; arr =原创 2022-04-08 10:22:51 · 423 阅读 · 0 评论 -
Leetcode1606 找到处理最多请求的服务器(线段树解法)
分析:将编号为0,1,..k-1,的k个服务器开始空闲的时间记做time[t],0<=t<k,刚开始所有的time都为0对于一个arrival[i],令x=i%k,我们想要知道以j= x,x+1,...,k-2,k-1,0,1,...,x-2,x-1顺序下的第一个j,使得time[j]<=arrival[i],可以发现[x,k-1]为一个连续的区间,[0,x-1]也是一个连续的区间。相当于在服务器中先查询[x,k-1]区间,如果找到直接返回;否则再查询[0,x-1]区间。这样就能够原创 2022-03-30 14:24:17 · 368 阅读 · 0 评论