BEARSEG - Editorial

These editorials are so hard to understand. 8 out of 10 times I am not able to understand what the editorial is trying to say and end up wasting a lot of time. Please make editorials more beginner friendly and explain the intuition behind the concepts well before diving into the solution.

2 Likes

can you explain with some example

@glebodin: It is \mathcal{O}(log N). Underlying structure in set is balanced binary search trees (BBSTs). In BBST, the following property is held for each node. For each node x, the value at its left child is \leq the value at x, and the value at the right child will be \geq value at x. So, you can find first element greater than or equal to some value by making a comparison at each node starting from root and deciding which child to go, to the left or to the right. The max number of comparisons will equal to the height of the tree, which is \mathcal{O}(log N) for BBST.

1 Like

can you tell me where my code is going wrong??

My O(n \log^2(n)) solution got accepted after some slight optimizations (in 1.94 s). https://www.codechef.com/viewsolution/13411903

How is this problem different from “http://stackoverflow.com/questions/31113993/maximum-subarray-sum-modulo-m” problem?

1 Like

1 3 1000000000 1000000000 1000000000 1000000000 Your solution output 0 5, but must be 0 6. Think about it(overflows sum[n]>2^32)

s overflows in your code, s=s+arr[i+j];

What’s the significance of writing “P(not necessarily prime)” in the question?

one implication I thought that instead of taking log(n) steps[map operation to find], one can iteratively search for the value from “left” because the numbers are not spaced that much as compared to situation where P is prime.

Aren’t the problems for Lunchtime supposed to be new?

Read my solution, I think it’s better for novice!