树状数组和线段树
开学了8
go on
展开
-
线段树模板二 (区间加 + 区间乘,求区间加)
https://www.luogu.com.cn/problem/P3373#include <iostream>using namespace std;#define ll long long #define ls (i<<1)#define rs (i<<1|1)const int N = 1e5 + 10;struct Node{ int l, r; ll data, add, mul;}tr[N<<2];ll input[N]原创 2021-09-22 10:55:15 · 52 阅读 · 0 评论 -
线段树模1
https://www.luogu.com.cn/problem/P3372#include<iostream>using namespace std;const int N = 1e5 + 10;#define ll long long struct Node{ int l, r; ll data, lz;}tree[N<<2];ll input[N];inline void pushup(int i){ tree[i].data = tree[原创 2021-09-21 22:00:37 · 69 阅读 · 0 评论 -
树状数组的变形(差分+数组数组)
暴力求解是不行的注意到差分后的一些性质1,6,8,5,10{1,6,8,5,10}1,6,8,5,10,对应差分数组1,5,2,−3,5{1,5,2,-3,5}1,5,2,−3,5区间[2,4] + 21,8,10,7,10{1,8,10,7,10}1,8,10,7,10,对应差分数组1,7,2,−3,3{1,7,2,-3,3}1,7,2,−3,3就是a[2]+2a[2]+2a[2]+2 ,a[5]−2a[5]-2a[5]−2#include <iostream>using na原创 2021-06-29 10:42:01 · 76 阅读 · 0 评论 -
树状数组模板(区间查询)
https://www.luogu.com.cn/problem/P3374区间查询#include <iostream>using namespace std;#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)int n,m;const int N = 5e5+10;int c[N];int lowbit(int x) {return x&-x;} // 计算父亲节点vo原创 2021-06-29 09:12:10 · 46 阅读 · 0 评论