P7811 [JRKSJ R2] Your Name.

Background

![](https://cdn.luogu.com.cn/upload/image_hosting/73iq08qk.png)

Description

You are given a sequence $a$ of length $n$. There are $m$ queries. For each query, you need to find the minimum value in the interval $[l,r]$ under modulo $k$, i.e., $\min\{a_i \bmod k \mid l \le i \le r\}$.

Input Format

The first line contains two integers $n,m$. The second line contains $n$ integers representing $a$. The next $m$ lines each contain three integers $l,r,k$, representing one query.

Output Format

For each query, output one answer per line.

Explanation/Hint

Idea: mcyl35, Solution: mcyl35, Code: mcyl35, Data: cyffff & mcyl35. This problem uses bundled testdata. | $\text{Subtask}$ | $n,m\le$ | $k,a_i\le$ | Special properties | Score | Dependency | | :-----------: | :-----------: | :-----------: | :-----------: | :-----------: | :-----------: | | $\text{1}$ | $10^4$ | $10^5$ | None | $3$ | $1$ | | $\text{2}$ | $10^5$ | $300$ | None | $6$ | $1$ | | $\text{3}$ | $10^5$ | $10^5$ | $k\ge 10^3$ | $10$ | $1\to2$ | | $\text{4}$ | $10^5$ | $10^5$ | None | $19$ | $2\to4$ | | $\text{5}$ | $3\times10^5$ | $10^5$ | Random testdata | $14$ | $1$ | | $\text{6}$ | $3\times10^5$ | $10^5$ | $k\ge 10^3$ | $2$ | $2\to3$ | | $\text{7}$ | $3\times10^5$ | $10^5$ | None | $46$ | $2\to5$ | Constraints: for $100\%$ of the testdata, $1\le n,m\le3\times10^5$, $1\le a_i,k\le 10^5$. The memory limit for the first $6$ subtasks is $256\text{MB}$, and the memory limit for the $7$th subtask is $128\text{MB}$. Translated by ChatGPT 5