sumq , codechef

codechef sumq

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

Samrat
Samrat De
Samrat

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
raghav7997 00:01, Mar 26
Raghav Grover

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.




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