function processQueries(T, testCases) {
const results = [];
for (let t = 0; t < T; t++) {
const [N, X] = testCases[t][0];
const A = testCases[t][1];
const Q = testCases[t][2];
const queries = testCases[t][3];
// Step 1: Create a boolean array for divisibility
const isDivisible = new Array(N + 1).fill(0);
for (let i = 1; i <= N; i++) {
if (A[i - 1] % X === 0) isDivisible[i] = 1;
}
// Step 2: Create a prefix sum array for fast range checking
const divCount = new Array(N + 1).fill(0);
for (let i = 1; i <= N; i++) {
divCount[i] = divCount[i - 1] + isDivisible[i];
}
// Step 3: Process each query
for (const [L, R] of queries) {
// Check if there's any element divisible by X in range [L, R]
if (divCount[R] - divCount[L - 1] > 0) {
results.push("Yes");
} else {
results.push("No");
}
}
}
// Output all results at once for faster execution in competitive environments
console.log(results.join("\n"));
}
// Example Usage:
const T = 1;
const testCases = [
[
[5, 4],
[2, 6, 2, 7, 8],
3,
[[3, 4], [2, 3], [5, 5]]
]
];
processQueries(T, testCases);