1810.Periodic RMQ Problem

Time Limit: 1s Memory Limit: 256MB

You are given an array a consisting of positive integers and q queries to this array. There are two types of queries:
1 l r x - for each index i such that l \le i \le r set ai=x. 2 l r - find the minimum among such ai that l \le i \le r.
We decided that this problem is too easy. So the array a is given in a compressed form: there is an array b consisting of n elements and a number k in the input, and before all queries a is equal to the concatenation of k arrays b (so the size of a is n \cdot k).

Input Format(From the terminal/stdin)

The first line contains two integers n and k (1 \le n \le 105, 1 \le k \le 104).

The second line contains n integers - elements of the array b (1 \le bi \le 109).

The third line contains one integer q (1 \le q \le 105).

Then q lines follow, each representing a query. Each query is given either as 1 l r x - set all elements in the segment from l till r (including borders) to x (1 \le l \le r \le n \cdot k, 1 \le x \le 109) or as 2 l r - find the minimum among all elements in the segment from l till r (1 \le l \le r \le n \cdot k).

Output Format(To the terminal/stdout)

For each query of type 2 print the answer to this query - the minimum on the corresponding segment.

Sample Input 1

Copy
3 1
1 2 3
3
2 1 3
1 1 2 4
2 1 3
 · \n
 · · \n
 \n
 · · \n
 · · · \n
 · · \n

Sample Output 1

Copy
1
3
 \n
 \n

Sample Input 2

Copy
3 2
1 2 3
5
2 4 4
1 4 4 5
2 4 4
1 1 6 1
2 6 6
 · \n
 · · \n
 \n
 · · \n
 · · · \n
 · · \n
 · · · \n
 · · \n

Sample Output 2

Copy
1
5
1
 \n
 \n
 \n

Submit

请先 登录

© 2025 FAQs