PRMQ-Wrong Answer

link to my code : https://www.codechef.com/viewsolution/15524867
question link : https://www.codechef.com/problems/PRMQ

I donno y im gettng WA…!
can anyone tell me wts wrong in my code ?

Thanks in advance :slight_smile:

The base condition in the function ll query(ll low,ll high,ll qlow,ll qhigh,ll x,ll y,ll pos) was wrong.

It would be -

if(qhigh < low || qlow > high || low > high){
    return 0;
}

instead of,


if(qlow < low || qhigh > high){
    return 0;
}

Here is your AC code: https://www.codechef.com/viewsolution/15529449

If you need any further help, let me know!

All the best!

1 Like

The size of the corresponding segment tree and lazy tree should be 2 * [2 ^ ceil(log2(n))] - 1 = O(4 * n).

You are taking the size of the trees to be 2 * n - 1.

Take them as 4 * n and you are good to go.

Here’s your AC solution: https://www.codechef.com/viewsolution/15529948

If you need any further help, let me know!

All the best!

1 Like

anyone pls check dis !!

tqq bro @alfarhanzahedi…!

link to my code : https://www.codechef.com/viewsolution/15529772
link to ques : https://www.codechef.com/problems/SPREAD

can u tell me wts wrong in dis @alfarhanzahedi ??

I have added the explanation as an answer to this question. Hope it helps!

tqq bro … once again @alfarhanzahedi…!