Almost 40 people were killed in violence across the country as Pakistan holds national elections marred by claims of misconduct.