FRJUMP - Editorial

The same code:
CodeChef: Practical coding for everyone
CodeChef: Practical coding for everyone

One in C++ 14 gets a WA and TLE(by 0.1 sec ) and the other(in C++ 4.3.2) gets AC,these things should not happen with a programmer :frowning:

Anyways what can be the reason ?

1 Like

Can anyone tell me why am i getting WA?
Here is my code link
https://www.codechef.com/viewsolution/10512326

We can do this question using sqrt decomposition also.Divide the array into sqrt n blocks and for each block maintain an array of sqrt n size in which ith element contains information required about the product of the elements in this block due to r=i.For r>=sqrt n just calculate the answer manually(it takes O(root n))and for r< sqrt n traverse the blocks to get the information.We can update in sqrt n time by checking divisors of that particular index and update in its block. So total complexity is O(n*root n).

I’m getting WA for subtask 2. Can somebody explain why? (I know the approach is not ideal, still)
https://www.codechef.com/viewsolution/10453146

Can anyone help me to optimize my code??

https://www.codechef.com/viewsolution/10504174

If N=50,say. and we update the 12th element. Then we have to change the value of product for r=1,2,3,4,6,12. How will we do that? Do we have to iterate through each value of r?

I got 95 points in the question since my solution did not pass the first subtask. Can anyone explain why?
https://www.codechef.com/viewsolution/10511094

Implemented as in editorial still getting WA. Can someone figure it why?
https://www.codechef.com/viewsolution/10515781

I dont understand why this additional EPS was needed in the power of 10.
Please answer…

This problem could be solved without the prior knowledge of square-root decomposition.
https://www.codechef.com/viewsolution/10448317

I did this problem without using sqrt-decomposition…I made an array which stores the new value of friendliness at pth index during update query…I never updated the array which stores enjoyment for different values of R. During query 2, I checked whether there is an any update of friendliness int the multiples of r. In this way i updated my Answer…
See my solution here for more clarity… CodeChef: Practical coding for everyone

Editorialist solution giving TLE for last 3 testcases . Why ?

can anyone explain me how to precompute the product array in O(nlogn) ?? I am getting it in O(n*sqrt(n)) .

In the editorialist code, what is the purpose of computing modulo inverse and multiplying with existing product of r along with y?

if (type == 1) {
  scanf("%d", &y);
  int iv = inv(a[x - 1]);
  long double nv = log10l((long double)y);
  for (int j = 0; j < (int)d[x - 1].size(); ++j) {
    int r = d[x - 1][j];
    prod[r] = 1LL * prod[r] * iv % MOD * y % MOD;
    slg[r] += nv - lg[x - 1];
  }
  a[x - 1] = y;
  lg[x - 1] = nv;
}

Another much easier method is to pre-compute answer for 1<= R<= min( N, 300). For R> 300 compute by iterating over 0 to N- 1, which takes O( N/ 300) since we make a jump of >300 during iteration. To update just alter the pre-computed values which takes O( min( 300, N)). So overall complexity becomes O( Q*N/300).

AC sol: CodeChef: Practical coding for everyone

1 Like

How do I get an idea of this type of solution?

Can anyone explain me the setter’s code:
for (int i=1; i<=min(pos-1, sq); i++){
if ((pos-1)%i==0){
dig[i]-=log10(a[pos]+0.0);
dig[i]+=log10(val+0.0);
remain[i]=inv;
remain[i]%=inf;
remain[i]
=val;
remain[i]%=inf;
Should’nt this be just min(pos,sq) as the setter had done 1 based indexing in his code?

i am using the same algo as given in solution still i am getting only 95 points. plz help.
solution link-
https://www.codechef.com/viewsolution/10910270

Not sure but I had testcases failing due to precision. Had to add a small precision check, EPS = 1E-9 to avoid WA on certain testcases.

1 Like

you are decomposing a number r into two products r = a * b. Where a <= b. Hence you need to search until square root of r only to find a and b. Hence, the name square root decomposition.