题目描述
We have a sequence of k numbers: d0,d1,...,dk−1.
Process the following q queries in order:
- The i-th query contains three integers ni, xi, and mi. Let a0,a1,...,ani−1 be the following sequence of ni numbers:$$ \begin{aligned} a_j = \begin{cases} x_i & ( j = 0 ) \\ a_{j - 1} + d_{(j - 1)~\textrm{mod}~k} & ( 0 \lt j \leq n_i - 1 ) \end{cases}\end{aligned}
$$Print the number of j (0≤j<ni−1) such that $(a_j~\textrm{mod}~m_i) \lt (a_{j + 1}~\textrm{mod}~m_i)$.
Here (y mod z) denotes the remainder of y divided by z, for two integers y and z (z>0).
我们有一串 k 数字: d0,d1,...,dk−1 .
请依次处理以下 q 个查询:
- i -查询包含三个整数 ni 、 xi 和 mi 。假设a0,a1,...,ani−1 是以下 ni 个数字的序列:
$$
\begin{aligned} a_j = \begin{cases} x_i & ( j = 0 ) \\ a_{j - 1} + d_{(j - 1)~\textrm{mod}~k} & ( 0 \lt j \leq n_i - 1 ) \end{cases}\end{aligned}
$$
打印 $j~(0 \leq j \lt n_i - 1)$ 中 $(a_j~\textrm{mod}~m_i) \lt (a_{j + 1}~\textrm{mod}~m_i)$ 的个数。
这里的 (y mod z) 表示两个整数 y 和 z (z>0) 的余数 y 除以 z 的余数。
输入格式
输入内容按以下格式标准输入:
k q
d0 d1 ... dk−1
n1 x1 m1
n2 x2 m2
:
nq xq mq
输出格式
打印 q 行。
i -th 行应包含对 i -th 查询的响应。
样例 #1
样例输入 #1
3 1
3 1 4
5 3 2
样例输出 #1
1
样例 #2
样例输入 #2
7 3
27 18 28 18 28 46 1000000000
1000000000 1 7
1000000000 2 10
1000000000 3 12
样例输出 #2
224489796
214285714
559523809
说明
数据规模与约定
- 所有输入值均为整数。
- 1≤k,q≤5000
- 0≤di≤109
- 2≤ni≤109
- 0≤xi≤109
- 2≤mi≤109
样例 1 解释
对于第一个查询,序列 { aj } 将是 3,6,7,11,14 。
- (a0 mod 2)>(a1 mod 2)
- (a1 mod 2)<(a2 mod 2)
- (a2 mod 2)=(a3 mod 2)
- (a3 mod 2)>(a4 mod 2)
因此,该查询的回复应为 1 。