CF1621I.Two Sequences
普及/提高-
通过率:0%
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 .
输入格式
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.
输出格式
Output q integers: values of Bi,j for required i , 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] .