Quantum simulation of second-quantized Hamiltonians in compact encoding