Yet another partition problem of contest 3 in dsa learning series

According to me my code’s time complexity is O(q*log( set.size() )) but then also its showing TLE in one test case .
Here is link of my code

Thanks in advance!!

You have 60 lines of similar-looking if-statements. Please explain your logic.

1 Like

I make a set of indexes of subarrays . In type 1 query I made 4 cases if the changed element before and after changing it’s value is divisible by the next element and the previous element is divisible by the changed element or not , according to this I insert and delete elements from the set.
I copy paste the same code after some changes because of the corner cases . Just focus on the else block .
After changing the value I am checking that if size of set is smaller then the previous one , then I simply update it .
In second query I am just finding the upper bound of the set and printing the element before the upper bounded element.

Why do you check the same condition multiple times in the same if-block? Because of short-circuiting, only one of the true conditions will be considered.

I guess your only culprit is on line 106, even though it seems like you have some other indexing issues (but if your code works as-is, it works). You don’t even use sAns at all, so you can probably get rid of it.

1 Like

Ohk…it was my bad…after getting rid of sAns…it worked…but I don’t get it why just assigning value took too much of time

Because you have a set with like 10^6 elements and you’re copying it 2 \cdot 10^5 times

1 Like

yup…thnx for your precious time…you are really great