Data Structures & AlgorithmsVery hardCodeforces Div2 B-D · ICPC regional
For the array [3, 1, 4, 1, 5, 9, 2, 6], how many subarrays have a product that is a multiple of 6?
- A. 20
- B. 0
- C. 5
- D. 60
Correct answer: A. 20
A subarray product is divisible by 6 exactly when it contains a multiple of 2 and a multiple of 3, which can be checked over all 36 subarrays.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Let A = [5, 3, 6, 2, 7, 1] (0-based), with P[0] = 0 and P[i] = A[0] ⊕ … ⊕ A[i−1]. What is A[2] ⊕ A[3] ⊕ A[4]?
- How many non-empty contiguous subarrays of [1, 2, 3, 0, 3] have XOR equal to 0?
- What is the maximum value of A[i] ⊕ A[j] over pairs i < j in A = [3, 10, 5, 25, 2, 8]?
- How many unordered pairs {i, j} with i ≠ j in [1, 3, 5, 7, 2, 4] satisfy A[i] ⊕ A[j] = 6?
- How many inversions does A = [7, 5, 3, 8, 1, 6, 2, 4] have, i.e. pairs i < j with A[i] > A[j]?
- P = [4, 1, 5, 2, 3] has 5 inversions. If its first element is moved to the end, how many inversions does the new array [1, 5, 2, 3, 4] have?