Cohomology of Artin groups of type ~A_n, B_n and applications