#P16097. [ICPC 2019 NAIPC] Cost of Living

[ICPC 2019 NAIPC] Cost of Living

题目描述

A newspaper columnist recently wrote a column comparing Disneyland’s price increases to other things in the economy; e.g., If gasoline were to have increased at the same rate as Disneyland’s admission since 1990, it would cost $6.66 per gallon.

Consider the prices of a number of commodities over a number of consecutive years. There is an inflation rate (inflation(x)>0\text{inflation}(x) > 0) for year xx to the next year (x+1)(x+1). Also, each commodity AA has a modifier (modifier(A)>0\text{modifier}(A) > 0) that is fixed for that commodity. So, for commodity AA in year x+1x+1:

$$\begin{aligned} \text{price}(A, x+1) = \text{price}(A, x) \cdot \text{inflation}(x) \cdot \text{modifier}(A) \end{aligned}$$

Unfortunately, the modifiers are unknown, and some of the prices and inflation rates are unknown.

Given some inflation rates, the prices for a number of commodities over a number of consecutive years, and some queries for prices for certain commodities in certain years, answer the queries.

输入格式

Each test case will begin with a line with three space-separated integers yy (1y101 \leq y \leq 10), cc (1c1001 \leq c \leq 100), and qq (1qyc1 \leq q \leq y \cdot c), where yy is the number of consecutive years, cc is the number of commodities, and qq is the number of queries to answer.

Each of the next y1y - 1 lines will contain a single real number rr (1.0r1.51.0 \leq r \leq 1.5, or r=1.0r = -1.0), which are the inflation rates. A value of 1.0-1.0 indicates that the inflation rate is unknown. The first inflation rate is the change from year 1 to year 2, the second from year 2 to year 3, and so on. Known inflation rates will conform to the limits specified; unknown but uniquely determinable inflation rates may not, and are only guaranteed to be strictly greater than zero.

Each of the next yy lines will describe one year’s prices. They will contain cc space-separated real numbers pp (1.0<p<1,000,000.01.0 < p < 1{,}000{,}000.0, or p=1.0p = -1.0), which indicate the price of that commodity in that year. A value of 1.0-1.0 indicates that the price is unknown.

Each of the next qq lines will contain two space-separated integers aa (1ac1 \leq a \leq c) and bb (1by1 \leq b \leq y), which represent a query for the price of commodity aa in year bb. All queries will be distinct.

All prices that can be uniquely determined will be strictly greater than zero and strictly less than 1,000,000.01{,}000{,}000.0. Values for prices and inflation rates in the input may not be exact, but will be accurate to 10 decimal places. All real values contain no more than 10 digits after the decimal point.

输出格式

Produce qq lines of output. Each line should contain a single real number, which is the price of the given commodity in the given year, or 1.0-1.0 if it cannot be determined. Answer the queries in the order that they appear in the input. Your answers will be accepted if they are within an absolute or relative error of 10410^{-4}.

4 2 2
1.3333333333
1.2500000000
-1
3.00 -1
4.00 8.00
5.00 10.00
-1 11.00
2 1
1 4
6.0000000000
5.5000000000