I feel the answer of 2nd input should be 5 and last case of 1st input should be 2(this will be 3 if table is round).Please tell whether my understanding of question is wrong or anything else.
Thanks
Given sample case is correct,read the question again word by word.
Thanks for your help but still not getting where i am failing.The deliciousness values are 5,4,-3.Don’t getting how they can sum up to give 6
its 4 -3 5
so 4-3+5=6
Thanks for your help but the last query of 1st input still concerns me.
According to me,The colorblind can see only 0,1,2 and the middle one has colorblindness=3 so this will not be selected.As the table is straight so the maximum is possible only when the last food is selected
i am also confused at the first sample case … last query should produce answer 2 according to me
also i want to be clear wether we have to sum up the previous answer or take xor? bcoz in given sample case both are producing same output
I thought the answer to the last query in first case was wrong too. But if you read the question carefully, you can see they mention “This person must choose an arbitrary contiguous subsequence of dishes on the table (possibly empty) and then eat all the dishes which this person can see”.
So what can we understand from this? This says you can choose any arbitrary contiguous sequence regardless of whether you can see all of them or not. It’s not necessary that you can see all of them. Hope it clears your doubt
can someone plz post the approach to solve this problem.
The sample test cases are correct. I agree there is a slight ambiguity in the problem statement though. The problem statement mentions that we have to take the value of c as the c xor previous answer for query type 1 and 2 only, however, as per the sample test cases we have to do this for type 3 too.
As for my approach, I was only able to solve the first 2 subtasks. Here’s how I did them -
Subtask 1: I applied max sum subarray O(N) dp from here and used a deque as the data structure.
Subtask 2: I applied square root decomposition. Instead of basing on the array, I based it on the range 0 to 2e9. I divided this into sizes of square root of 2e9. Whenever I got a c, I added the corresponding value of d to the appropriate block. Since in this subtask, d is always positive, we’ll always choose the whole array as the solution subarray and eat all dishes that we can see. Thus this solution will work.