A. Merge
time limit per test
1 second
memory limit per test
32 megabytes
input
standard input
output
standard output

Phitsanulok province and the city of Phitsanulok was called "the city of two rivers" because it is located between Nan River and Khwae Noi River. Phitsanulok province is a big province and it is easy to travel to many famous tourist destinations such as Phu Hin Rong Kla National Park, Thung Salaeng Luang National Park, Man Daeng Waterfall, and Kang Song Waterfall. Following the border opening after the COVID emergency has passed, Prof. TOI of POSN.NU. is tasked to plan the promotion of tourism within the province. For his research to follow the academic standards, Prof. TOI assigns two research assistants who are proficient in digital systems, Mr. X and Mr. Y, the task of surveying electric vehicle charging stations, reporting the location and the number of charging outlets at each station, throughout routes to tourist destinations in order to help tourists with electric vehicles plan energy management for their vehicles. Prof. TOI asks Mr. X to survey AC (alternating current) charging stations and Mr. Y to survey DC (direct current) charging stations, where the results will be further used for the task. When Mr. X measures the distances, he measures from the westernmost edge of Phitsanulok province towards the east. (If the distance is negative, the location is to the west of Phitsanulok.)

Mr. X's report includes $$$N$$$ AC charging stations, where the distance to each station is $$$x_1,x_2,\ldots,x_N$$$ units, and the number of charging outlets at each station is $$$s_1,s_2,\ldots,s_N$$$. Mr. Y uses the same distance measurement scheme. Mr. Y's report includes $$$M$$$ DC charging stations, where the distance to each station is $$$y_1,y_2,\ldots,y_M$$$ units, and the number of charging outlets at each station is $$$t_1,t_2,\ldots,t_M$$$. Prof. TOI then takes both of their reports to calculate and design the tourism plan. However!!! suddenly a problem emerges. Prof. TOI receives a report that Mr. Y misunderstands the reporting procedure, collecting and recording incorrect distance values in the report. Prof. TOI needs to quickly correct the mistakes and deliver the results before he can make it to the opening ceremony of the Olympiad in Informatics. Prof. TOI discovers that the mistakes exhibit a linear pattern, and thus he can take the distances $$$y_1,y_2,\ldots,y_M$$$ and recalculate them into

$$$\bar y_j = \alpha y_j+\beta$$$ for $$$j=1,\ldots,M$$$

Because of limited timeframe, Prof. TOI has to merge the data from Mr. X and Mr. Y in order to create the TOI-chart to help with planning. The horizontal axis values of the chart are the values of $$$x_i$$$ for $$$i=1,\ldots,N$$$, or $$$\bar y_j$$$ for $$$j=1,\ldots,M$$$, sorted in increasing order, and the vertical axis values are the number of charging outlets $$$s_i$$$ for $$$i=1,\ldots,N$$$, or $$$t_j$$$ for $$$j=1,\ldots,M$$$, unless $$$x_i=\bar y_j$$$ for some $$$i$$$, $$$j$$$, in which case the vertical axis values are the number of charging outlets $$$s_i+t_j$$$. Then, Prof. TOI needs to take the merged location and outlet count numbers to create the new data, with the locations $$$z_k$$$ for $$$k=1,\ldots,P$$$, where $$$z_1 \lt z_2 \lt \cdots \lt p$$$, and the number of charging outlets $$$u_1,u_2,\ldots,u_P$$$, respectively. The data is then analyzed into slots, where the number of slots is $$$u_1+u_2+\ldots+u_P$$$ and

  • slots $$$i=1,\ldots,u_1$$$ have value $$$z_1$$$
  • slots $$$(u_1+1),\ldots,(u_1+u_2)$$$ have value $$$z_2$$$
  • ...
  • slots $$$(u_1+\cdots+u_{P-1}+1),\ldots,(u_1+\cdots+u_{P-1}+u_P)$$$ have value $$$z_P$$$

Example

Mr. X's report includes distances to each of the $$$N=9$$$ charging stations and the number of AC charging outlets as follows:

station $$$i$$$123456789
$$$x_i$$$1234567810
$$$s_i$$$121357621

Mr. Y's report includes distances to each of the $$$M=8$$$ charging stations and the number of DC charging outlets as follows:

station $$$j$$$12345678
$$$y_j$$$124567910
$$$t_j$$$12463221
Figure 1. Charts displaying the relationship between distances and charging outlet counts from (a) Mr. X's report, and (b) Mr. Y's report

Prof. TOI corrects the report using $$$\alpha=2$$$ and $$$\beta=−5$$$ to obtain new Mr. Y's report with modified $$$\bar y_j = 2y_j − 5$$$

station $$$j$$$12345678
$$$y_j$$$-3-135791315
$$$t_j$$$12463221
Corrected Mr. Y's report
Figure 2. Corrected Mr. Y's report
Figure 3. Example of distance measurement

From Mr. X's report and corrected Mr. Y's report, the merged data and TOI-chart appear as follows:

station $$$k$$$12345678910111213$$$P=14$$$
$$$z_k$$$-3-1123456789101315
$$$u_k$$$121253117922121
Figure 4. TOI-chart created by Prof. TOI

When the data from TOI-chart is analyzed into slots, the result is as follows:

slot123456789...46474849
value-3-1-1122333...10131315

From the example above, the value at slot 1 is -3, the values at slots 2 and 3 are -1 ... the value at slot 48 is 13, and the value at slot 49 is 15.

Your Task

Write an efficient program to determine the value at slot $$$k$$$.

Input

There are $$$Q+5$$$ lines of input:

Line 13 integers separated by a single space.

The first integer is $$$N$$$, denoting the number of AC charging stations recorded by Mr. X.

The second integer is $$$M$$$, denoting the number of DC charging stations recorded by Mr. Y.

The third integer is $$$Q$$$, denoting the number of questions asking for the values at slot $$$k$$$.

Let $$$1 \leq N,M \leq 100{,}000$$$ and $$$0 \leq Q \leq 50{,}000$$$.

Line 2$$$N$$$ integers separated by a single space, denoting the distance of $$$x_1, x_2, \ldots , x_N$$$ units to each charging station, as recorded by Mr. X. Let $$$1 \leq x_1 \lt x_2 \lt \ldots \lt x_N \leq 1{,}000{,}000$$$.
Line 3$$$N$$$ integers separated by a single space, denoting the number of AC charging outlets $$$s_1, s_2, \ldots, s_N$$$ at each charging station, as recorded by Mr. X. Let $$$1 \leq s_i \leq 100$$$ for $$$i = 1, ... ,N$$$.
Line 4$$$M$$$ integers separated by a single space, denoting the distance of $$$y_1, y_2, \ldots , y_M$$$ units to each charging station, as recorded by Mr. Y. Let $$$1 \leq y_1 \lt y_2 \lt \ldots \lt y_m \leq 1{,}000{,}000$$$.
Line 5$$$M$$$ integers separated by a single space, denoting the number of DC charging outlets $$$t_1, t_2, \ldots, t_M$$$ at each charging station, as recorded by Mr. Y. Let $$$1 \leq t_j \leq 100$$$ for $$$j = 1, \ldots ,M$$$
Line $$$l+5$$$ to Line $$$Q+5$$$ for $$$l = 1,\ldots,Q$$$3 integers separated by a single space.

The first integer is $$$\alpha_l$$$ where $$$1 \leq \alpha_l \leq 100$$$.

The second integer is $$$\beta_l$$$ where $$$-10^6 \leq \beta_l \leq 10^6$$$, for calculating $$$\bar y_j = \alpha y_j+\beta$$$.

The third integer is $$$k_l$$$ denoting the slot position $$$k_l$$$ where $$$1 \leq k_l \leq \sum_i s_i + \sum_j t_j$$$

Output

There are $$$Q$$$ lines of output:

Line $$$l$$$Each line contains 1 integer denoting the data at slot $$$k_l$$$ for $$$l=1,\ldots,Q$$$
Scoring

Notices regarding the test sets are as follows:

Test GroupMaximum attainable score in this groupCondition(s)
18$$$1\leq N,M,Q \leq 100$$$
213$$$x_i = i$$$, $$$\forall i$$$ and $$$y_j = j$$$, $$$\forall j$$$ and $$$N, M \lt 5{,}000$$$ and $$$Q \lt 10{,}000$$$
317$$$\alpha=1$$$ and $$$\beta=0$$$
422$$$N=1$$$ and $$$s_1=1$$$
540No additional constraints
Examples
Input
9 8 8
1 2 3 4 5 6 7 8 10
1 2 1 3 5 7 6 2 1
1 2 4 5 6 7 9 10
1 2 4 6 3 2 2 1
1 0 1
1 0 2
1 0 3
1 0 8
2 -5 1
2 -5 2
2 -5 3
2 -5 8
Output
1
1
2
4
-3
-1
-1
3
Input
5 2 6
1 2 3 4 5
1 1 1 1 1
1 5
1 1
1 0 1
1 0 3
1 1 1
1 1 3
1 -2 1
1 -2 3
Output
1
2
1
2
-1
2
Input
5 2 6
1 2 3 4 5
1 1 1 1 1
1 5
1 1
1 -5 1
1 -5 2
1 -5 3
3 -10 3
3 10 3
3 20 3
Output
-4
0
1
2
3
3
Note

Recommended programming tips

If the contestant uses cin/cout, it is recommended to add 2 lines as the following:

std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);