50 likes | 215 Views
HKOI 2013 Junior Group. Queueing. Problem. Gold member 1 2345678 Ordinary member 0 1234567 Non-member 210987654321. Sample. 4 09876543 12345678 123456789012 210987654321 2 1 4 12345678 09876543 123456789012 210987654321
E N D
HKOI 2013 Junior Group Queueing
Problem • Gold member • 12345678 • Ordinary member • 01234567 • Non-member • 210987654321
Sample 4 09876543 12345678 123456789012 210987654321 2 1 4 12345678 09876543 123456789012 210987654321 456789012345 12345678 345678901234 09876543 01234567 210987654321 12345678 456789012345 09876543 01234567 345678901234 210987654321
50% Solution • For each query, look for the Ai-th person served in O(N) • For each step, just consider the first 2 people and their number of times of ‘being stalled’, the next person gets served must be one of them
100% Solution • Precompute j-th served person, for 1<=j<=N in O(N) • O(1) for answering each query • How? • Read 50% solution again • When looking for the Ai-th served person, you know all the k-th served person, for 1<=k<=Ai