Election officials, including some in battleground states, plan to spend millions in federal money to help protect America’s ballot boxes from cyberattacks.