question link: https://www.codechef.com/problems/SUMQ
answer link: https://www.codechef.com/viewsolution/17942109
I am pretty much sure, that my code is correct, still it is giving wrong answer.
The logic which i have used is, for a particular y, sum= (X(j) + Y) * (Z(k) +Y), where j or k can range between (0 and p) & (0 and r) repectively. Then i have expanded the sum calculating X(j)*Z(k) , Y{ X(j) + Z(k) } , Y^2 separately. Still the code is not running :'( :'(
can u point out the mistake..??
Asked by: Samrat_De on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.
for(i=0;i<q;i++)
{ unsigned long long int p=1;
for(j=count_a;j<p&&b[i]>=a[j];j++)
{ sum_a=(sum_a+a[j])%m;
count_a++;
size_a++;
}
......
p is the size of the array A, but you are using local variable whose name is also p, in the above loop,since the priority is given to local variable, hence the value of p will become 1, thats why your loop for array A runs only once;
Second thing is that the approach you are using will get TLE, since p,q and r are order of 10^5, so your approach won't work.
Hint : Use prefix sum and binary search to make your code optimised.