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.