Comments (4)
Not sure if I understood your query correctly, but you have to modify SegmentTree::fun
to perform whatever operation you need to.
T fun(T a, T b) { return std::min(a, b); }
from cc.
Thanks for considering this and Sorry that I was not clear
I know how to use this template as i learned classic segment trees
I provided this code as reference
Iam asking about the code in your repository
As I am learning lazy segment trees
https://github.com/the-hyp0cr1t3/CC/blob/master/%E6%9C%AB%20Snippets/Segment%20trees/Recursive%20%2B%20Range%20updates%20(lazy%20prop).cpp
Is there any generic function that I can write instead of changing every where as I did in above code
Or how should I do that ( where should I change for mins,max,sum,or gcd,LCM etc for any cumulative functions)
You can explain by taking any example
The default templete is for min i think?
I hope I am clear this time
Thanks in advance!
from cc.
Oh I see, thanks for clarifying. You'll have to make changes in the Node
struct.
For example, for range max query and range sum update, it would look something like this:
const int64_t inf = 2e18;
struct Node {
using V = int64_t;
using L = int64_t;
bool pending{false};
V val; L lazy{};
Node(V val = -inf): val(val) {} // default value
Node(const Node& l, const Node& r) // merge two nodes
: val(std::max(l.val, r.val)) {}
void apply_lazy(int len) { val += lazy; } // update node
operator V() const { return val; }
};
Similarly, range gcd query and range assignment updates would look like:
struct Node {
using V = int64_t;
using L = struct Lazy {
V lzy;
Lazy(V lzy = 0): lzy(lzy) {} // default value
operator V() const { return lzy; }
void operator+=(const Lazy& rhs) { lzy = rhs.lzy; } // combine with other lazy
};
bool pending{false};
V val; L lazy{};
Node(V val = 0): val(val) {} // default values
Node(const Node& l, const Node& r) // merge two nodes
: val(std::gcd(l.val, r.val)) {}
void apply_lazy(int len) { val = lazy; } // update node
operator V() const { return val; }
};
from cc.
hey Thanks !
from cc.
Related Issues (7)
- Add driver functions( main() function ) HOT 1
- GUIDE HOT 7
- Suggestion on Two Pointers HOT 1
- Hook
- Ferris Wheel HOT 1
- A note on prefix sums
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cc.