Help with question D-Val in October Cookoff

Can someone explain how to solve the question?
Link - CodeChef: Practical coding for everyone

1 Like

Fix d, count answers for a b c and e f g independently. I’ll just address a b c since e f g is the exact same.

Precalculate an array ans(c, d): Number of pairs (a, b) that satisfy the conditions for given c, d. If d is processed in a way such that A(d) is decreasing, then there are events when new bs vare valid, therefore the answer for all d can be processed in a total of O(N). Added with c, it’s O(N ^ 2).

Then fixing d, fixing c and e gives us answer for triplets on left and right in O(1).

1 Like

just one question @just1star in all contests you only solve the problems with the least submissions(in oct long you solved jiit) .If you submit all problems for just few contest I am pretty sure you can easily become 6-7 star very easily and quickly.

I hafta live true to my name though.

4 Likes

Thanks for the solution.
If you could provide some code it would be really very helpful.

No one is stopping you from visiting his profile and viewing his submission.
Anyway here it is 27499647

2 Likes

Thanks.:sweat_smile: