I have invented a new data structure that takes O(n) = n memory only and can handle range minimum and maximum queries in O(log^2 n) worst case per query.
Yes, you read that right. You just need as many elements as the size of the original array.
This is much better memory-wise than a segment tree.
I will reveal the new paradigm-shifting RMQ if I get enough upvotes.
What it can do:
- Range minimum and maximum queries in O(log^2 n) worst case.
- Updates to any position in O(log^2 n) worst case.
- It takes just n elements for our new data structure.
This is dead serious, and I will link a CSES solution in this blog once I reveal the method.
Here we go,
This is the solution for CSES range dynamic queries. https://cses.fi/problemset/task/1649/
.
_
The idea is i am using existing Fenwick tree with modified query and update logic to achieve the results. There's myth that Fenwick trees cannot handle range min max with updates. This disproves the urban myth.
It is much much simpler than segment tree in my humble opinion as the Fenwick tree is probably the simplest data structure in existence.
UPDATE: I also have range update techniques.









Can you prove that it is $$$log^2$$$?
And also explain how the functions work.
Sure, lets handle update first. It takes in k which is the least bit which after which max logn zeros. Hence, logn for each traverse up gets multiplied by logn. Btw, while loop is just iterating over the children of node to recalculate. In Fenwick tree each node has max logn children.
For query, we are trying to find the segments of powers of two that cover the range. Moving from right to left. It can be shown that r-1 is subtracted at most logn times because each time the lsb moves to the left because we are trying to decrease it. So logn times logn.
good. thx.
This is an optimization of what you're mentioning, though it needs
2Nelements.Update portion looks similar to mine. However its using two Fenwick tree which is too much for my brain lol.
There may be even better strategies especially for the query portion. It could be optimised. Let's wait for ideas.
I have invented a new data structureI don't think so, next time learn how to use search engines pls: https://mirror.codeforces.com/blog/entry/121381
This blog you provide is only for query.
my RMQ can handle updates too. However your blog doesn't handle updates. It's just static query only.
And here is another method using Fenwick Tree, it can handle updates: oi-wiki.
(I'm sorry it's Chinese, but I have only found this.)
The blog claims segment tree can do anything but Fenwick can't. Its just false claim. Segment tree only has two children for each node. However Fenwick has logn. So it can do anything segment tree can but it will take logn times more steps because each node is responsible for more than two child nodes.
Its just like the difference between b trees, red black trees and avl tree. What makes them different is how the nodes are organized.
Some trees are binary, some are ternary. Fenwick is logarithmy lol.
Why did u delete your recent blog?
And also what did u reply to me in that blog?
People were thinking this was a joke. I deleted to remove negative attention.