/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 196ms 13.621 MiB
#2 Wrong Answer 196ms 13.582 MiB

Code

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);

Information

Submit By
Type
Submission
Problem
P1128 Roy and Product
Contest
Brain Booster #7
Language
JavaScript (Node.js v18.19.1)
Submit At
2024-11-05 15:05:50
Judged At
2024-11-11 02:31:34
Judged By
Score
0
Total Time
196ms
Peak Memory
13.621 MiB