Republican successes in last month’s state legislative elections reinforced the party’s upper hand in drawing congressional district lines, but both parties are preparing for a long fight on the ground and in the courts.