#P7837. Identifying Special Customers
Identifying Special Customers
Identifying Special Customers
Zi provides a sequence of length ( n ) where the ( i)-th element corresponds to customer number ( i ). All ordinary customers are colored blue and all special customers are colored purple. It is known that there are ( m ) special customers with purple positions. Importantly, the purple positions are very few and are almost uniformly distributed at random.
The value ( a_i ) at position ( i ) is assigned according to the formula:
[
a_i=\begin{cases} s & \text{if } i=1\ a_{i-1}+k & \text{if } i>1\end{cases}
]
Mistia can ask queries of the form l r
to obtain the sum of the values ( a_i ) for all blue positions in the interval ( [l, r] ) (i.e. skipping the purple positions). If you are able to determine all the special customers (i.e. all purple positions), then you should output a line of the form -1 p1 p2 ... pm
, where ( p_i ) are the indices of the special customers in non-decreasing order.
Note: After each operation (query or final answer), you should flush the output buffer. For example, in C++ use fflush(stdout)
or cout.flush()
; in C use fflush(stdout)
; in Java use System.out.flush()
; in Python use stdout.flush()
; in Pascal use flush(output)
; and please consult the relevant documentation for other languages.
inputFormat
The input consists of two lines:
- The first line contains four integers \( n \), \( m \), \( s \) and \( k \), where \( n \) is the length of the sequence, \( m \) is the number of special customers, \( s \) is the first term of the sequence, and \( k \) is the common difference.
- The second line contains \( m \) distinct integers representing the indices of the special (purple) customers. These indices are in the range \( [1,n] \) and may be given in any order.
outputFormat
Output a single line that starts with -1
followed by the ( m ) special customer indices in non-decreasing order, separated by spaces.
sample
10 2 1 2
3 8
-1 3 8