Given an array of N(N<=10^5) elements and -10^9<=A[i]<=10^9. Q(Q<=10^5) queries are there of two types:
L R K: Add K to all numbers in range [L,R] in array.
L R: Find no. of positive elements>0 in range [L,R].
I Thought of segment tree with lazy propagation but not able to understand what info to be stored in each node. Please suggest some approach for this problem. @freeloop
I think you will need a range min query and range max query based 2 segment trees and using that you can answer the queries.
e.g. if max element in a range is less than 0 you return 0,
if min element in a range is greater than 0 you return r - l + 1.
else you go to the next level and see if one of the above condition holds.
Use lazy propagation to update the maximum and minimum values of the 2 trees. That shouldn’t be too hard.
I am not at all sure about this. Any counter case/feedback is appreciated!
I think you can solve this problem by maintaining a Venice Set in each node. I learned this thing just few days back and so may be I am completely wrong! From here on, I assume you have atleast had a look on the blog I mentioned.
My thought:
Query of type 1 : We can use Technique as mentioned in blog with lazy propagation.
Query of type 2 : We basically need to find numbers > water_level in Set of range [L,R]. As the values are stored in multiset, we can binary search on value of water_level to find the answer.