版本比较
线段树模板
正文
增加 5 行删除 5 行
21 行未改动22232425262728293040 行未改动7172737475767778798081828384858687888990919250 行未改动21 行未改动f(rs(x),mid+1,r,tag[x],fun2);tag[x]=0;}inline void update(const int&l,const int&r,const T&k,const int&ql,const int&qr,const int&x,T (*fun2)(T a,T b)){if(l<=ql&&r>=qr){//完全覆盖t[x]=fun(t[x],k*(qr-ql+1));tag[x]=fun(tag[x],k);return;}40 行未改动if(l<=mid)res=fun(res,query(l,r,1,mid,ls(1)));if(r>mid)res=fun(res,query(l,r,mid+1,num,rs(1)));return res;}inline int&getnum(){return num;}inline T&scan(int x){return a[x];}};}```- 用法:`xds::STree<线段树所存储的数据类型,数据范围(线段树最大存储的数据数量),操作方法(函数)>`- 注意:> 1. 创建线段树时**能且只能使用以下两种方法** _(如果发现更多使用方法或修改方法求评论或私信,不胜感激)_ :>> ```cppxds::STree<int,100009,add> *tree=new xds::STree<线段树所存储的数据类型,数据范围(线段树最大存储的数据数量),操作方法(函数)>(输入的数据个数,即数列数字的个数);xds::STree<线段树所存储的数据类型,数据范围(线段树最大存储的数据数量),操作方法(函数)> tree();```> 2. 暂时只支持单个操作(即暂不支持[P3373 【模板】线段树 2](https://www.luogu.com.cn/problem/P3373)。如需支持,需要在模板增加一维。~~虽然不是很难`(maybe)`~~,但我太懒了,就先鸽这吧。- 例子:[P3372 【模板】线段树 1](https://www.luogu.com.cn/problem/P3372):50 行未改动21 行未改动22232425262728293040 行未改动7172737475767778798081828384858687888990919250 行未改动21 行未改动f(rs(x),mid+1,r,tag[x],fun2);tag[x]=0;}inline void update(const int&l,const int&r,const T&k,const int&ql,const int&qr,const int&x,T (*fun2)(T a,T b)){if(l<=ql&&r>=qr){//完全覆盖t[x]=fun(t[x],k*(qr-ql+1));tag[x]=fun(tag[x],k);return;}40 行未改动if(l<=mid)res=fun(res,query(l,r,1,mid,ls(1)));if(r>mid)res=fun(res,query(l,r,mid+1,num,rs(1)));return res;}inline int&getnum(){return num;}inline T&scan(int x){return a[x];}};}```- 用法:`xds::STree<线段树所存储的数据类型,数据范围(线段树最大存储的数据数量),操作方法(函数)>`- 注意:> 1. 创建线段树时**能且只能使用以下两种方法** _(如果发现更多使用方法或修改方法求评论或私信,不胜感激)_ :>> ```cppxds::STree<int,100009,add> *tree=new xds::STree<线段树所存储的数据类型,数据范围(线段树最大存储的数据数量),操作方法(函数)>(输入的数据个数,即数列数字的个数);xds::STree<线段树所存储的数据类型,数据范围(线段树最大存储的数据数量),操作方法(函数)> tree();```> 2. 暂时只支持单个操作(即暂不支持[P3373 【模板】线段树 2](https://www.luogu.com.cn/problem/P3373)。如需支持,需要在模板增加一维。~~虽然不是很难`(maybe)`~~,但我太懒了,就先鸽这吧。- 例子:[P3372 【模板】线段树 1](https://www.luogu.com.cn/problem/P3372):50 行未改动