Speechify's task manager records field updates for each task as they arrive. Given an unordered list of update events, reconstruct the final state of every task after applying only the latest update for each field.
Each event is a dictionary with four keys: task_id (integer), field (string), value (any JSON value), and timestamp (integer). Return a dictionary mapping each task_id to another dictionary of its final field values. For the same (task_id, field), the event with the largest timestamp wins. If two events for the same (task_id, field) have the same timestamp, the later event in the input list wins.
def restore_task_state(events):