I have polished my implementation after ten long days of refactoring and minimizing the number of variables required to keep track of each action. I added hardcore random numbers tests to tally results against brute force verifier.
I have tested it against a dozen problems. It's a continuous process.
Please just run the program it will automatically test against the brute force algorithm for range update and queries.
The code should be extremely easy to understand from what it was ten days ago. The rest of logic is just propagation of lazy values from top to the bottom of the intervals.
Solution for below CSES
https://cses.fi/alon/task/1651
Hacker earth hard https://www.hackerearth.com/problem/algorithm/range-update-range-max-queries
Solution for the above hacker earth hard problem with generic combine methods
SPOJ GSS3
https://www.spoj.com/problems/GSS3/
CSES range update range sums hard
https://cses.fi/problemset/task/1735/
this should be much more readable as its just collecting intervals, propagating lazy values to them and then going all the way to the root to update impacted parents.
I will keep polishing. I have many ideas to take it to the next level e.g hashing, book keeping cleanup, macro hacks etc. YMMV








https://www.spoj.com/problems/GSS1/
Classic segment tree problem solved using Fenwick tree.
Please ignore the fast int code. Performance comparable to segment tree.
The basic idea is to cover a range [left, right] we need at max log square powers of two.
Keep removing all powers of two from right until we reach left value. If we cant remove a power we can always decrease by 1.
If mergeing two consecutive segment is constant time. Whole range only take log square.
I visited sereja and brackets after ten years.
It's running much faster than segment tree.
https://mirror.codeforces.com/problemset/problem/380/C
As always as the whole picture becomes clearer, the code is always getting shorter lol.
Trying to get nails for my new hammer. Let's keep hammering.