Confusing transistor outputs in diagram
The transistors in the diagram are all NPN.
The two greyed out transistors are effectively switched off.  But the outputs are still connected to the 5V line through the 1k resistors.  So the outputs are pulled up by the resistors to 5V.
The two white transistors are switched on.  This pulls the output down to (approximately) 0V.  The important thing is that the transistor is between the output and ground (0V).  So turning the transistor on connects the output to ground, not to 5V.