#K916. Subarray Sum Divisibility

    ID: 38011 Type: Default 1000ms 256MiB

Subarray Sum Divisibility

Subarray Sum Divisibility

You are given an array A of n integers and a divisor k. You are also provided with q queries. Each query is described by two integers L and R, representing the 1-indexed boundaries of a subarray. For each query, determine if the sum of the elements in the subarray A[L..R] is divisible by k.

Formally, for each query, check if \[ \left(\sum_{i=L}^{R} A_i\right) \mod k = 0 \] Write a program that reads input from stdin and outputs the answer:

  • Output "YES" if the subarray sum is divisible by k.
  • Output "NO" otherwise.

inputFormat

The input is read from standard input (stdin) in the following format:

n k
A[1] A[2] ... A[n]
q
L1 R1
L2 R2
... 
Lq Rq

Here, n is the number of elements in the array, k is the divisor, and q is the number of queries. Each of the next q lines contains two integers, representing the indices L and R (1-indexed) of the subarray.

outputFormat

For each query, output a line containing either "YES" if the sum of the subarray A[L..R] is divisible by k, or "NO" otherwise. The output is written to standard output (stdout).

## sample
5 3
1 2 3 4 5
3
1 3
2 5
1 5
YES

NO YES

</p>