Kick Start 2019 Round A Contention

$\DeclareMathOperator*{\argmax}{arg\,max}$

Topic Link

Subject to the effect

A row of seats $ N $, $ 1 to $ numbered from left to right $ N $.

$ Q $ has a seat reservation request, the request wants $ $ I $ predetermined number from all seats L_i $ $ $ of R_i.

$ Q $ can handle requests in any order, while processing a request, the allocation of the corresponding section of the seat are not assigned to the request.

We ask each request final set to the minimum number of seats most likely how much?

Limits

  • Time limit: 30 seconds per test set.
  • Memory limit: 1GB.
  • $T = 100$.
  • $ 1 \ N \ 10 ^ 6 $.
  • $ 1 \ The L_i \ the R_i \ k $.
  • $ 1 \ Q \ the $ 30,000.
  • For at least 85 of the test cases, $Q \le 3000$.

analysis

Observation 1: Number of seats $ i $ requests to be processed and obtained by the pretreatment $ i - $ 1 sequence regardless of request.

Observation 2:
set $ A, B $ is adjacent to two requests. Suppose if the first processing $ A $, then $ A $ get $ A $ seats; if the first processing $ B $, then $ B $ get $ b $ seats; and provided $ A, B $ two requests were obtained $ c $ seats, obviously nothing to do with the order $ c $ $ a, B $ to be treated, and there is $ a + b \ ge c $ . You may wish to set up $ a> b $. If the minimum value of the first rear seat $ A $ $ B $ is obtained for the two requests $ \ min (a, c - a) = c - a $; if the first $ B $ $ A $, the minimum to $ \ min (b, c - b) $. Noting $ b \ ge c - a $ and $ c - b> c - a $, therefore, $ \ min (b, c - b) \ ge \ min (a, c - a) $; in other words, for the phase o two requests, that request should be assigned to handle fewer seats.

Note: The order of the processing may satisfy the above conditions is not unique, because $ a, b $ depends on the magnitude relation of those requests before processing.

I can not figure out here.


Official explanations

We can observe that for a chosen ordering of the requests, the number of seats that the system books in the last request does not depend on the ordering of the previous $Q - 1$ requests. So, we could start by finding the request to be processed last and move backwards towards the earlier requests.

I can understand this period, but the question is how can you determine which request should be processed last in an optimal solution?


I figured out.

Consider a number of requests in any order, press this arrangement to operate, the minimum number of seats available per request referred to this end "arrangement minimum."

Key observation:

Take a request from any arbitrary arrangement $ k $ ($ k> 1 $) request, the remaining $ k - 1 are arranged a certain minimum $ request originally less than the minimum request $ k $ is arranged .

Defined functions $ f (x) $ denotes the last (i.e., number of $ Q $) processing requests $ x $, $ x $ can get the number of seats. The $ f (x) $ referred to as the maximum value of $ m $.

For any permutation $ P $ Q $ request of: = p_1, p_2, \ dots , p_Q $, set a minimum value of $ a $.
Suppose $ f (p_Q) <m $ , the $ a \ le f (p_Q) <m $, and provided $ f (p_i) = m $ ; considering arranged $ P ': = p_1, p_2 , \ dots, p_ { i -1}, p_ {i + 1}, \ dots, p_ {Q} $, set a minimum value of $ b $, so there $ b \ ge a $.

Consider the arrangement $ P '': = p_1, p_2, \ dots, p_ {i -1}, p_ {i + 1}, \ dots, p_ {Q}, p_i $, set a minimum value of $ c $, Yi see $ c = \ min (b, m) $.
Since $ b \ ge a $ and $ m> a $ therefore, $ c \ ge a $. So the $ \ argmax_x f (x) $ can lead to put the final optimal solution.

Guess you like

Origin www.cnblogs.com/Patt/p/11618433.html