What is it i am doing wrong?
Question link:https://hack.codingblocks.com/contests/c/452/299
Code:https://ide.codingblocks.com/s/46509
ALPHA SCORE Idea to be used
https://ide.codingblocks.com/s/46638
The logic used was amazing but the code had lots of bugs. I have corrected them. Now it passes all the cases.
Do let me know in case of any problmes.
1 Like
Thanks a lot.
Can you tell me what did I do incorrectly or what was i missing?
- You weren’t sorting the array in cross function which was required.
- Answer should be mod 1000000007 which was missing.
- Base case in merge function was missing.
- In cross function, the value that was added to alpha number was incorrect.
See the corrected version of your code.
2 Likes
I am sorry but can you explain this line of code
alphasum=(alphasum+(a[i]*(right-j+1))%M)%M;
Can we just not add the a[i]?
if a[i]<a[j], this means that answer at j will be added with a[i]. Thats why you are saying that we have to add a[i]. But note that is a[i] < a[j], then a[i] < a[j+1] and a[i] < a[j+2] … as second array from j till end is also sorted. So the answer is added right-j+1 times.
1 Like