Time-resolved nonlinear ghost imaging