Having sex but it’s painful

When I have sex it will feel fine at first but then my virginal starts to swell up then making the sex painful what do I need to do ?