CF1621I.Two Sequences
NOI/NOI+/CTSC
通过率:0%
时间限制:8.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Consider an array of integers C=[c1,c2,…,cn] of length n. Let's build the sequence of arrays D0,D1,D2,…,Dn of length n+1 in the following way:
- The first element of this sequence will be equals C: D0=C.
- For each 1≤i≤n array Di will be constructed from Di−1 in the following way:
- Let's find the lexicographically smallest subarray of Di−1 of length i. Then, the first n−i elements of Di will be equals to the corresponding n−i elements of array Di−1 and the last i elements of Di will be equals to the corresponding elements of the found subarray of length i.
Array x is subarray of array y, if x can be obtained by deletion of several (possibly, zero or all) elements from the beginning of y and several (possibly, zero or all) elements from the end of y.
For array C let's denote array Dn as op(C).
Alice has an array of integers A=[a1,a2,…,an] of length n. She will build the sequence of arrays B0,B1,…,Bn of length n+1 in the following way:
- The first element of this sequence will be equals A: B0=A.
- For each 1≤i≤n array Bi will be equals op(Bi−1), where op is the transformation described above.
She will ask you q queries about elements of sequence of arrays B0,B1,…,Bn. Each query consists of two integers i and j, and the answer to this query is the value of the j-th element of array Bi.
考虑一个长度为 n 的整数数组 C=[c1,c2,…,cn]。我们按如下方式构造长度为 n+1 的数组序列 D0,D1,D2,…,Dn:
- 该序列的第一个数组即为 C:D0=C。
- 对每个 1≤i≤n,数组 Di 由 Di−1 按如下方式构造:
- 找出 Di−1 中字典序最小的长度为 i 的子数组;然后,Di 的前 n−i 个元素等于 Di−1 中对应的前 n−i 个元素,而 Di 的后 i 个元素等于所找到的长度为 i 的子数组中对应的元素。
若数组 x 可通过从数组 y 的开头删除若干(可能为零个或全部)元素、并从其末尾删除若干(可能为零个或全部)元素而得到,则称 x 是 y 的子数组。
对数组 C,记 Dn 为 op(C)。
Alice 有一个长度为 n 的整数数组 A=[a1,a2,…,an]。她将按如下方式构造长度为 n+1 的数组序列 B0,B1,…,Bn:
- 该序列的第一个数组即为 A:B0=A。
- 对每个 1≤i≤n,数组 Bi 等于 op(Bi−1),其中 op 即上述定义的变换。
她将向你提出 q 个查询,每个查询针对数组序列 B0,B1,…,Bn 中的某个元素。每个查询包含两个整数 i 和 j,其答案为数组 Bi 的第 j 个元素的值。
输入格式
The first line contains the single integer n (1≤n≤105) — the length of array A.
The second line contains n integers a1,a2,…,an (1≤ai≤n) — the array A.
The third line contains the single integer q (1≤q≤106) — the number of queries.
Each of the next q lines contains two integers i, j (1≤i,j≤n) — parameters of queries.
第一行包含一个整数 n(1≤n≤105)—— 数组 A 的长度。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤n)—— 数组 A。
第三行包含一个整数 q(1≤q≤106)—— 查询的数量。
接下来的 q 行中,每行包含两个整数 i、j(1≤i,j≤n)—— 查询的参数。
输出格式
Output q integers: values of Bi,j for required i, j.
输出 q 个整数:所需 i、j 对应的 Bi,j 的值。
输入输出样例
输入#1
4 2 1 3 1 4 1 1 1 2 1 3 1 4
输出#1
2 1 1 3
说明/提示
In the first test case B0=A=[2,1,3,1].
B1 is constructed in the following way:
- Initially, D0=[2,1,3,1].
- For i=1 the lexicographically smallest subarray of D0 of length 1 is [1], so D1 will be [2,1,3,1].
- For i=2 the lexicographically smallest subarray of D1 of length 2 is [1,3], so D2 will be [2,1,1,3].
- For i=3 the lexicographically smallest subarray of D2 of length 3 is [1,1,3], so D3 will be [2,1,1,3].
- For i=4 the lexicographically smallest subarray of D3 of length 4 is [2,1,1,3], so D4 will be [2,1,1,3].
- So, B1=op(B0)=op([2,1,3,1])=[2,1,1,3].
在第一个测试用例中,B0=A=[2,1,3,1]。
B1 按如下方式构造:
- 初始时,D0=[2,1,3,1]。
- 当 i=1 时,D0 中长度为 1 的字典序最小的子数组是 [1],因此 D1=[2,1,3,1]。
- 当 i=2 时,D1 中长度为 2 的字典序最小的子数组是 [1,3],因此 D2=[2,1,1,3]。
- 当 i=3 时,D2 中长度为 3 的字典序最小的子数组是 [1,1,3],因此 D3=[2,1,1,3]。
- 当 i=4 时,D3 中长度为 4 的字典序最小的子数组是 [2,1,1,3],因此 D4=[2,1,1,3]。
- 因此,B1=op(B0)=op([2,1,3,1])=[2,1,1,3]。
输入解题思路,AI测评打分。不知道怎么写?