Change in Mo's algo sort function gives different results

Revision en1, by kishore_p, 2018-08-01 21:56:31

I used Mo's algo to solve this problem .

First compare function: It gives me wrong answer Submission1

bool comp(query &a,query &b)
{
 int x=a.L/bsize;
 int y=b.L/bsize;
 
 if(x!=y)
 return x<y;
 if(x&1)
 return (a.R > b.R);
 else
 return (a.R < b.R);
}

Second function : Gives me AC Submission2

bool comp(query &a,query &b)
{
 int x=a.L/bsize;
 int y=b.L/bsize;
 
 if(x!=y)
 return x<y;
 else
 return a.R < b.R;
}

First one is an optimisation,but not able to find why it gives wrong answer

Tags mos algorithm, sqrt-decomposition, complexity optimization

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English kishore_p 2018-08-01 21:56:31 756 Initial revision (published)