Yes, because now you are speaking of the venue: I cannot concentrate in class/school.
Meanwhile, this one is still good when you are speaking of the topic or object of concentration: I cannot concentrate on class/school.
As you can see with these particular nouns, they can be considered either the place of concentration or the object of concentration.