Lehmer codes and Poincaré polynomials of Schubert varieties in types A and B