need some help in UVa 11402 - Ahoy, Pirates!

problem link: https://uva.onlinejudge.org/external/114/11402.pdf
I tried this problem with segment tree(I think its the best way to do so). There is a problem with the invert operation in my code.Probably the problem is in query() or up() . Can someone help me to find it out?

Thanks in advance.

code is too long and can be found here

1 Like

Hey dear, just an advise, if your code is this long, you can submit it at ideone.com and provide link here. (Actually this long code might irritate some people, and prevention is better than cure! :slight_smile: )

dude, Thanks. made post shorter :smiley:

Your code is giving me TLE even for basic cases (even if there is no inverse involved).

Are you sure that there is no infinite loop anywhere? I would have loved to investigate further but I got mid-sems from tomorrow, kinda time crunch. Can you check for any possibility of infinite loop in your code?

Maybe thats because I took input from file and posted with those things active (sorry!). Try commenting “FRO” on starting of main function(line 152)

1 Like

And thanks for viewing the code. Thats surely one of the worst code you have ever seen :stuck_out_tongue: (well i haven’t seen anything worse than this yet!)

Your update function is not working properly.

// in update section

if(L>=i&& R<=j)
    {
        lazy[ps]=v;
    }
here you have to also update lazy array for children of parent node.
After some corrections you code should look this.
// if(L>=i&& R<=j)
{
    lazy[ps]=v;
// update lazy for left child
 code 
// update right child 
code
return 
}
May be this can be helpful.
Ps: sorry for my bad English.
Ps: I have solved this problem after you posted here.
1 Like

Also I have not read your whole code just checked update section and found that there is no return , so there can be more bugs.

I guess i am updating lazy array of children in up() function. plz check up() function too!

I would love to help further but midsems are a pain XD. I will review again when I am done with preparation for 2 exams tomorrow. :slight_smile:

I have looked on your code and I found there are some more errors. So it is not easy task to debug your code for better understanding you can take help from my code https://pastebin.com/pF9Y2uPx