Dear Sasameiyuki
Thanks for contacting Top China Travel!
For your question, you can buy train tickets in advance. Since December 30, 2016, the train ticket pre-sale period has been adjusted: Most train tickets can be booked 30 days in advance before the departure day through Online (12306.cn), mobile phone APP and telephone (95105105), and 28 days in advance through train station, ticket outlets and ticket vending machine.
TCT suggests travellers to book train ticket as early as they can, in case of the availability of the ticket. There are four way for guests to buy train ticket in China: buy ticket at the Railway Station, online, by telephone or through travel agencies. More useful information you can find at page How to Book China Train Tickets.
There are 27 trains depart from Qufu to Beijing. The earliest one departs at 08:07 am from Qufu East and the last one departs at 21:09. The trains take from 2h11m to 11h13m, duration vary from the different train. The fastest train takes only 2 hours and 11 minutes.
Any further request or question, please feel free to contact with us.
Best Reegards
Joy Duan