#P9212. 「蓬莱人形」

「蓬莱人形」

Background

Mokou, who never grows old and never dies, can she still be called a "human"?

A human who has gone beyond life and death is unbelievable in itself.

Problem Description

To prove what humans are capable of, you need to solve a problem.

Given a sequence a=[a1,a2,,an]a=[a_1,a_2,\cdots,a_n]. There are qq queries:

  • Each time you are given a pair (x,y)(x,y), a modulus mm, and an interval [l,r][l,r]. Find how many i[l,r]i\in [l,r] satisfy (ai+x)modm<(ai+y)modm(a_i+x)\bmod m<(a_i+y)\bmod m.

Input Format

The first line contains two positive integers n,qn, q, representing the length of the sequence and the number of queries.

The second line contains nn positive integers a1,a2,,ana_1,a_2,\cdots,a_n, describing the sequence aa.

The next qq lines each contain five integers li,ri,xi,yi,mil_i,r_i,x_i,y_i,m_i, describing one query.

Output Format

Output qq lines in total. On the ii-th line, output the answer to the ii-th query.

10 5
4 3 2 5 8 5 3 3 1 2
1 10 3 7 6
4 10 5 5 4
2 7 1 2 9
5 9 3 4 7
1 3 5 1 8
4
0
6
3
2

Hint

Sample Explanation

  • For the first query, the indices of elements that satisfy the condition are 1,2,7,81, 2, 7, 8.
  • For the second query, no element satisfies the condition.
  • For the third query, the indices of elements that satisfy the condition are 2,3,4,5,6,72, 3, 4, 5, 6, 7.
  • For the fourth query, the indices of elements that satisfy the condition are 5,6,95, 6, 9.
  • For the fifth query, the indices of elements that satisfy the condition are 1,21, 2.

Constraints and Notes

For all testdata, 1n1051\le n\le 10^5, 1q5×1051\le q\le 5\times 10^5, 1ai,xi,yi,mi1051\le a_i,x_i,y_i,m_i\le 10^5, 1lirin1\le l_i\le r_i\le n.

Translated by ChatGPT 5