#P9882. [EC Final 2021] Vision Test

    ID: 9247 Type: RemoteJudge 3000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>2021Special JudgeO2优化ICPC

[EC Final 2021] Vision Test

题目描述

Prof. Pang has an extraordinary vision. He can see the pixels on a 4K monitor. To test Prof. Pang's vision, Prof. Shou will show Prof. Pang several pixels and let Prof. Pang guess a straight line that contains these pixels. Given kk pixels with coordinates (i,yi)(i, y_i) (0i<k0\le i<k), Prof. Pang must find nonnegative integers a,ba, b and cc (which represent the line y=ax+bcy=\frac{ax+b}{c}) such that yi=ai+bcy_i=\lfloor \frac{ai+b}{c} \rfloor for all 0i<k0\le i<k.

Prof. Shou will ask Prof. Pang multiple questions. They are given as follows: Prof. Shou has a fixed array x1,,xnx_1,\ldots, x_n. For each question, Prof. Shou chooses a range in the array, xl,,xrx_l,\ldots, x_r. Then he defines yi=xl+iy_i=x_{l+i} for 0irl0\le i\le r - l and asks Prof. Pang to answer the question for the rl+1r-l+1 pixels (0,y0),,(rl,yrl)(0, y_0), \ldots, (r-l, y_{r-l}).

Please help Prof. Pang answer all the questions. For each question, output the answer with the minimum (c,a,b)(c, a, b) in lexical order.

It is guaranteed that the answer exists when Prof. Pang chooses the whole array x1,x2,,xnx_1, x_2, \dots, x_n. So the answer always exists when Prof. Pang chooses an interval of this array.

输入格式

The first line contains a single integer TT (1T1051\le T\le 10^5) denoting the number of test cases.

For each test case, the first line contains an integer nn (1n1051\leq n\leq 10^5). The second line contains nn numbers x1,,xnx_1, \ldots , x_{n} (0xi1090\leq x_i\leq 10^9).

The next line contains an integer qq (1q1051\le q\le 10^5) denoting the number of questions.

Each of the following qq lines contains two integers l,rl, r (1lrn1\le l\le r\le n).

It is guaranteed that the sum of nn over all test cases will not exceed 10510^5 and that the sum of qq over all test cases will not exceed 10510^5.

输出格式

In the order of input, output one line with three integers a,b,ca, b, c denoting the answer for each question.

题目大意

给定一个长度为 nn 的数组 xx,接下来你有 qq 次询问。

ii 次询问给出一个区间 l,rl,r,设 k=rl+1k=r-l+1,你提取出 xx 数组下标在 l,rl,r 之间的区间 yi=xi+l(0i<k)y_i=x_{i+l}(0\le i<k)

考虑 kk 个点 (0,y0),(1,y1)(k1,yk1)(0,y_0),(1,y_1)\dots(k-1,y_{k-1})。你需要找到一条直线的三个整数参数 a,b,ca,b,c,满足 0i<k,yi=ai+bc\forall 0\le i<k,y_i=\lfloor \frac{ai+b}{c}\rfloor。若有多条这样的直线,输出 (c,a,b)(c,a,b) 三元组字典序最小的一个。

保证对于整个数组,即 l=1,r=nl=1,r=n 的询问一定存在一组合法的解。

n,q105n,q\le 10^5,多组询问。

3
5
1 1 2 2 2
4
1 5
1 1
3 5
2 3
5
1 2 3 4 6
3
1 5
2 4
3 5
3
0 3 5
1
1 3

1 4 3
0 1 1
0 2 1
1 1 1
5 4 4
1 2 1
3 6 2
5 1 2