I am getting tle in this question, mera approach ye hai ki mai do max aur min tree build kr rha hu, hr ek node pe ye uske subtree kaa max and min hai, query time pe me agr koi max tree node ki value <k to mai niche nhi jaunga, aur age kisi node kaa min >=k ho to. Subtree ka count return kr dunga,
Max query - 1 getting tle
Hi
This has a simpler approach
Approach:
make a combined array of numbers and all the queries .
sort it in descending order (if it’s query then use k for sorting)
then create a segtree that gives you number of non zero element between l to r …(considering all the elements of array are initially zero)
then process your sorted array :
if
it’s array element then update value in segtree …
else
if array element represent a query then query on your segtree to find number of non zero elements between
l to r. (this will ensure all the elements will be greater than k …think yourself)
Hit like if you get it
Cheers!
If you still have doubt do post.
combinaed array of numbers and queries mtlb??