sumq , codechef

codechef sumq

question link:

answer link:

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..??

Samrat De

Please Log in to answer

Note: Your answer should not be too short. Please wait a few seconds for the editor to load

Please make sure the answer is not too short

1 Answer

raghav7997 00:01, Mar 26
Raghav Grover

		{	unsigned long long int p=1;
			{	sum_a=(sum_a+a[j])%m;


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.

Please make sure the answer is not too short
No Comments yet