407511: GYM102821 C Cycle Function
Description
Fish is learning functions! He has a linear function $$$f(x) = Ax + B$$$ and $$$N$$$ numbers $$$x_1,x_2,\cdots,x_N$$$. Now he is curious about for each function $$$g(x)$$$ in
how to calculate the difference between $$$f(g(x))$$$ and $$$g(f(x))$$$.
As smart as Fish is, he soon comes up with a function $$$D(x)=|f(g(x))-x|+|g(f(x))-x|$$$ and uses the sum over $$${x_1,x_2,\cdots,x_N}$$$ as the difference.
Can you tell him all the differences immediately?
InputThe first line of input contains an integer $$$T$$$, representing the number of test cases.
Then for each test case:
The first line contains two integers $$$N$$$, $$$M$$$ as mentioned above and then two real numbers $$$A$$$, $$$B$$$ indicating the given function $$$f(x) = Ax + B$$$.
The second line contains $$$N$$$ real numbers $$$x_1,x_2,\cdots,x_N$$$.
Then $$$M$$$ lines follow, each line containing two real numbers $$$c_i$$$, $$$d_i$$$ indicating a function $$$g_i(x)=c_ix+d_i$$$ mentioned above.
All numbers in the same line are separated by one space.
OutputFor each test case, you should output Case $$$x$$$: in the first line, where x indicates the case number starting from 1.
Then $$$M$$$ lines follow, the $$$i$$$-th line of which contains a real number representing the difference for given function $$$g_i(x)$$$.
Your answers will be considered correct if its absolute error does not exceed $$$10^{-6}$$$.
ExampleInput2 3 2 2.0 3.0 1.0 2.0 3.0 0.4 -2.0 0.6 -5.0 3 2 2.5 2.0 1.0 2.0 3.0 0.4 -2.0 0.6 -5.0Output
Case 1: 7.800000 28.200000 Case 2: 12.600000 36.900000Note
$$$1\le T\le 100$$$
$$$1\le N, M\le 10^5$$$
$$$-100 \le A,B,x_i,c_i,d_i \le 100$$$
For $$$90\%$$$ test cases: $$$\max(N, M) \le 1000$$$