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