### Abinash's blog

By Abinash, 6 years ago,

I submit 2 solution of this problem , both are almost same . But this one need 2.31 sec and that one need 1.49 sec , why ?

If I change the second solution the compare function as

bool cp( Q a, Q b ) {
int ax=a.L/tmt,bx=b.L/tmt;
if ( ax!=bx ) return ax<bx;
return (ax&1)?a.R<b.R:a.R>b.R;
}


and change the value of as

tmt=(int)(1.514*sqrt(m)+1);


then it need .96sec to pass , why ?

• 0

 » 6 years ago, # |   0 The struct query is different for both of them . In one you have declared l and r as long long while in the other one(the faster one) they are declared as int.
•  » » 6 years ago, # ^ |   0 And what about the compare function and value of tmt?
 » 6 years ago, # |   0 Try to submit the program taking your array a as int. Using long long making the computation slow. 9738918.No need to declare struct element as long long and also no need to take input as 64 bit if the input can be fit into 32 bit. 9738898