Help in FCTRE

bool comp(query a , query b)
int x = a.l/BLK;
int y = b.l/BLK;

if(x != y)
return x < y;

return x % 2 ? a.r < b.r : a.r > b.r;


if x==y then then u are sorting values according to r , then why are u using x%2?

modular multiplicative inverse means like this
(6/2)%5 =(6%5)((multiplicative inverse of 2%5)%5)%5=(6%5)(3%5)%5 =3%5=3.
what is its importance?

can anyone help me to find error in the code FCTRE, everything looks correct, unable to detect the error

when x == y
we need to sort queries based on R pointer (true) but we won’t always sort queries as a.r < b.r
we try to minimize the movement of right pointer more by sorting queries as
a.r < b.r if block size of first query is odd
a.r > b.r

for more information read these two articles

  1. Mo's Algorithm - Codeforces
  2. How do I optimize my Mo's algorithm solution? - Codeforces

you are making mistake in init( ) function

for(ll j=2*i;j<=N;j++)
  ll cnt=0;
  ll x=j;

here you have written j++ in the for loop
it should be j += i