Tap here to switch tabs
Problem
Submissions

Problem: Find X Value of Array II

Try to solve the Find X Value of Array II problem.

Statement

You are given an integer array nums, an integer k, and a 22D integer array queries where each query is given in the form queries[i] = [index_i, value_i, start_i, x_i].

For each query in order, perform the following actions:

  1. Update nums[index_i] to value_i. This modification persists for all subsequent queries.

  2. Count the number of subarrays starting at index start_i (that is, contiguous subarrays nums[start_i..j] where start_i ≤j<\le j < nums.length) such that the product of the elements in the subarray modulo k is equal to x_i.

Return an integer array containing the result for each query.

Constraints:

  • 1≤1 \le nums[i] ≤109\le 10^9

  • 1≤1 \le nums.length ≤105\le 10^5

  • 1≤1 \le k ≤5\le 5

  • 1≤1 \le queries.length ≤2×104\le 2 \times 10^4

  • queries[i] == [index_i, value_i, start_i, x_i]

  • 0≤0 \le index_i ≤\le nums.length −1- 1

  • 1≤1 \le value_i ≤109\le 10^9

  • 0≤0 \le start_i ≤\le nums.length −1- 1

  • 0≤0 \le x_i ≤\le k −1- 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find X Value of Array II

Try to solve the Find X Value of Array II problem.

Statement

You are given an integer array nums, an integer k, and a 22D integer array queries where each query is given in the form queries[i] = [index_i, value_i, start_i, x_i].

For each query in order, perform the following actions:

  1. Update nums[index_i] to value_i. This modification persists for all subsequent queries.

  2. Count the number of subarrays starting at index start_i (that is, contiguous subarrays nums[start_i..j] where start_i ≤j<\le j < nums.length) such that the product of the elements in the subarray modulo k is equal to x_i.

Return an integer array containing the result for each query.

Constraints:

  • 1≤1 \le nums[i] ≤109\le 10^9

  • 1≤1 \le nums.length ≤105\le 10^5

  • 1≤1 \le k ≤5\le 5

  • 1≤1 \le queries.length ≤2×104\le 2 \times 10^4

  • queries[i] == [index_i, value_i, start_i, x_i]

  • 0≤0 \le index_i ≤\le nums.length −1- 1

  • 1≤1 \le value_i ≤109\le 10^9

  • 0≤0 \le start_i ≤\le nums.length −1- 1

  • 0≤0 \le x_i ≤\le k −1- 1