Formation of a p-type quantum dot at the end of an n-type carbon nanotube