Almost same code but one got TLE and one AC.

Правка en1, от imposter_syndrome, 2017-01-23 15:35:17

Hello folks! I am new to codeforces and this was my first problem. I was trying powerful arrays http://codeforces.com/problemset/problem/86/D problem.

I used MO's algorithm to solve it.

My first approach was this **http://codeforces.com/contest/86/submission/24070204**

But this got TLE on test case 43. Now when I made a different function checkAns(); in my next submission http://codeforces.com/contest/86/submission/24070298 , it got AC..

All I changed was I put

L=queries[i].L;
    R=queries[i].R;

    while(currentL<L){
       del(currentL);
       currentL++;
    };
    while(currentL>L){
       add(currentL-1);
       currentL--;
    };

    while(currentR<R){
       add(currentR+1);
       currentR++;
    };
    while(currentR>R){
       del(currentR);
       currentR--;
    };

this part of my code in a separate function checkAns(i); I am not getting how this got AC if earlier one was getting TLE. Also isn't function call increases time taken?? Please mention if there is something different on codeforces' platform.

Thanks in advance :)

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский imposter_syndrome 2017-01-23 22:50:20 5
en2 Английский imposter_syndrome 2017-01-23 22:49:32 625
en1 Английский imposter_syndrome 2017-01-23 15:35:17 1112 Initial revision (published)