摘要: 题目描述 思路 1. 0 和 1 开方之后不会改变,对 0, 1 节点打上标记 2. 如果孩子节点都打上标记了,说明这些孩子节点的和不会改变,那么父节点也打上标记 3. 对于打上标记的点,change 的时候直接 return 代码 c++ include include int n, m; lon 阅读全文
posted @ 2019-09-10 10:17 cabbage-leaf 阅读(147) 评论(0) 推荐(0) 编辑
摘要: "题目描述" 思路 代码 c++ include include long long n, m; struct { long long at[1000005], arr[1000005 1; this build(k build(k add(k, l, r, v); return; } int mi 阅读全文
posted @ 2019-09-09 22:05 cabbage-leaf 阅读(221) 评论(0) 推荐(0) 编辑
摘要: "题目描述" 思路 代码 c++ include include int n, m; struct { int at[1000005]; long long int arr[1000005 1; this build(k build(k r || y 1; this change(k change( 阅读全文
posted @ 2019-09-09 20:45 cabbage-leaf 阅读(158) 评论(0) 推荐(0) 编辑
摘要: "题目描述" 思路 1. 询问的是区间[L, R],完美序列的开始下标 = L 2. 二分查找序列中满足开始下标大于L的第一个位置x 3. ST算法求解[x, R]的最大长度 y 4. x L 和 y 的最大值为结果 代码 c++ include define max(a,b) ((a) (b) ? 阅读全文
posted @ 2019-09-09 16:49 cabbage-leaf 阅读(129) 评论(0) 推荐(0) 编辑
摘要: "题目描述" 思路 代码 c++ include include // include //using namespace std; define max(a, b) ((a) (b) ? (a) : (b)) define min(a, b) ((a) (b) ? (b) : (a)) int n 阅读全文
posted @ 2019-09-09 12:58 cabbage-leaf 阅读(162) 评论(0) 推荐(0) 编辑
摘要: "题目描述" 思路 RMQ 问题 ST算法 代码 c+++ include include define max(a, b) ((a) (b) ? (a) : (b)) int n, m; int arr[100005]; int f[100005][21], log[100005]; inline 阅读全文
posted @ 2019-09-09 11:29 cabbage-leaf 阅读(255) 评论(0) 推荐(0) 编辑
摘要: 一维树状数组 c++ int lowbit(int n) return n & ( n); void update (int x, int y) { for (; x update(x, y) 区间查询 = sum(x)实现的是求[1, x]的和,求[L, R]的和就是sum(R) sum(L 1) 阅读全文
posted @ 2019-09-09 10:19 cabbage-leaf 阅读(182) 评论(0) 推荐(0) 编辑
摘要: "题目描述" 思路 update是从(x,y)处往下更新,sum是求(x,y)到(0, 0)的和 lowbit(x) 表示二进制下x的最低位的1与它后面的0构成的树,那么对于奇数来说就是1 |x| 1 | 2 | 3 | 4 | 5| 6| | | | | | | | | |二进制| 1| 10 | 阅读全文
posted @ 2019-09-09 09:09 cabbage-leaf 阅读(369) 评论(0) 推荐(0) 编辑
摘要: "题目描述" 思路 因为树状数组update是会一直更新到最后的节点,查询的也是端点的情况,所以用两个树状数组来维护一段区间 每次给定一个区间(l, r)变换, 就是update(l, 1, start), update(r, 1, ed) 注意 update(r, 1, ed), 而不是updat 阅读全文
posted @ 2019-09-09 07:26 cabbage-leaf 阅读(124) 评论(0) 推荐(0) 编辑
摘要: "题目描述" 思路 用一个数组记录lowbit的值 代码 c++ include include int n, k; char st; int arr[500005], lowbit[500005]; void update(int x, int y) { while (x 阅读全文
posted @ 2019-09-08 21:02 cabbage-leaf 阅读(196) 评论(0) 推荐(0) 编辑