解いたので記録として載せておく。
最適解かどうかはわからない。
result.php
$input_line = fgets(STDIN);
$users = [];
$update_list = [];
$first_line = explode(" ", $input_line);
$people_num = $first_line[0];
$update_num = $first_line[1];
$sum_line = $first_line[0] + $first_line[1];
for ($i = 0; $i < $sum_line; $i++) {
$s = fgets(STDIN);
$s = str_replace(array("\r\n","\r","\n"), '', $s);
$s = explode(" ", $s);
if($people_num > $i){
$users[$i]["nickname"] = $s[0];
$users[$i]["old"] = $s[1];
$users[$i]["birth"] = $s[2];
$users[$i]["state"] = $s[3];
}
if($update_num <= $i) {
$update_list[$i]["user_num"] = $s[0];
$update_list[$i]["new_name"] = $s[1];
}
}
foreach ($users as $user_i => $user_val){
foreach ($update_list as $up_i => $up_val){
if($up_val["user_num"] == $user_i + 1){
$users[$user_i]["nickname"] = $up_val["new_name"];
}
}
$result = implode(' ', $users[$user_i]);
echo $result . "\n";
}