Differents??

Revision en7, by Omega1, 2015-07-19 13:56:19

Today I solved problem E. A Simple task that was given at last contest,and I find something intersting and new for me, posible and for other users.Why if I declare k,l,st,dr as a global variable I get TLE on test 9 and if I declare as a local variable my code past all tests?

Can someone explain why?

k=x;
for (l=26;l>=1;l--) {
    st=lower_bound(g[l].begin(),g[l].end(),x)-g[l].begin();
    dr=upper_bound(g[l].begin(),g[l].end(),y)-g[l].begin();
    for (;st<dr;st++) {
         g[l][st]=k; k++;
    }
}

get TLE;

int k=x;
for (int l=26;l>=1;l--) {
    int st=lower_bound(g[l].begin(),g[l].end(),x)-g[l].begin();
    int dr=upper_bound(g[l].begin(),g[l].end(),y)-g[l].begin();
    for (;st<dr;st++) {
         g[l][st]=k; k++;
    }
}

past all tests.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en8 English Omega1 2015-07-20 13:57:56 4
en7 English Omega1 2015-07-19 13:56:19 28 Tiny change: ' variable `int k,int st,int dr,int l` [my code]' -> ' variable [my code]'
en6 English Omega1 2015-07-19 13:50:11 30 Tiny change: 'ble `int k=x,int st,in' -
en5 English Omega1 2015-07-19 13:22:56 511 Tiny change: 'ain why?\n`k=x;\n\' -
en4 English Omega1 2015-07-19 13:14:40 6 Tiny change: 'ssion/12114162) past all' -> 'ssion/12115404) past all'
en3 English Omega1 2015-07-19 13:10:58 16 Tiny change: 'sion/12114547?locale=en) past all' -> 'sion/12114162) past all'
en2 English Omega1 2015-07-19 11:55:25 1
en1 English Omega1 2015-07-19 11:54:33 499 Initial revision (published)