eolymp
bolt
Try our new interface for solving problems
Problems

Sparse Tables

Sparse Tables

The array with $n$ integers is given. Write a program that answers the question: find the minimum on a segment between $u$ and $v$ inclusively. \InputFile The first line contains three positive integers $n, m~(1 \le n \le 10^5, m \le 10^7)$ and $a_1~(1 \le a_1 < 16714589)$ --- the number of elements in array, the number of queries and the first element in an array respectively. The second line contains two positive integers $u_1$ and $v_1~(1 \le u_1, v_1 \le n)$ --- the first query. The elements $a_2, a_3, ..., a_n$ are given with the next formula: $$ a_{i+1} = (23 \cdot a_i + 21563)~mod~16714589 $$ For example, if $n = 10, a_1 = 12345$, we get the next array: $$ a = (12345, 305498, 7048017, 11694653, 1565158, 2591019, 9471233, 570265, 13137658, 1325095) $$ The queries are generated this way: $$ u_{i+1} = ((17 \cdot u_i + 751 + ans_i + 2i)~mod~n) + 1 $$ $$ v_{i+1} = ((13 \cdot v_i + 593 + ans_i + 5i)~mod~n) + 1 $$ where $ans_i$ is the answer to the $i$-th query. \OutputFile Print $u_m, v_m$ and $ans_m$ (the values for the last query and the answer to it).
Time limit 2 seconds
Memory limit 128 MiB
Input example #1
10 8 12345
3 9
Output example #1
5 3 1565158
Author В.Гольдштейн
Source Зимние сборы в Харькове 2010 День 2