Problem 1: Carpet laying
At first glance, cry, carpet coverage... it seems to be a 2-dims line segment tree. It is so difficult at the beginning. Again, you only need to find a point, make a decisive question, and simulate it. (Note: From the enumeration with a large label to a small one, if there is a carpet that meets the requirements, the output will be returned .)
(If the entire article is not completed, the code will not be sent .)
Problem 2: Select Inn
The simulation will time out, so we use a dynamic planning method.
Use $ \ Text {sum} \ left [I \ right] $ to indicate the total number of CAF s that meet the requirements on the way from INN 1 to inn I. Naturally, the time complexity of $ \ Text {o} \ left (n \ right) $ is needless to say. You can read and collect statistics while reading.
Set the three arrays to $ f [1], F [2], and f [3] $, respectively, set a temporary variable $ T $, $ color [I] $ to the color number of inn I (fog ...). $ A [I] $ that is, the total number of solutions selected by a later person in the I-colored Inn (of course, an accumulation variable must be set for output, for example, $ S $ ), $ B [I] $ indicates the total number of valid inns scanned at this time (this color), and $ C [I] $ indicates the total number of valid CAF in this color before this time (of course, do not use the same color ). then, add the result to $ S $.