Given an array A, containing positive integers. You need to perform some queries on it.
You will be given Q Queries. Each query will have one string and two integers.
Each Query can be of two type :
“C” X Y - Here “C” says that we need to Change the integer at position X to integer Y.
“A” X Y - Here “A” say that we are Asked number of primes in the the range : [X, Y] (inclusive)
For each Query of type 2, you need to calculate an integer denoting the answer to it.
NOTE
1. Assume 1-indexing for all queries.
2. Your code will be run on multiple test cases (< 10). Make sure to come up with an optimised solution and take care of clearing global variables.
CONSTRAINTS
1 <= Size of A <= 4 * 10^4
1 <= A[i] <= 10^6
1 <= Number of Queries (Size of B, C, D) <= 5 * 10^4
INPUT FORMAT
You will be given 4 Arrays:
A: Array of integers
B,C,D : Arrays denoting the query. Here in the i-th query, B[i] is the String, C[i] and D[i] represents the ranges.
OUTPUT FORMAT
Return an integer array, where each of the element represents the answer to the queries of type 2, in chronological order.
EXAMPLE INPUT
A : [ 1, 3, 121, 20, 17, 26, 29 ]
B : ["A", "C", "A"]
C : [1, 3, 1]
D : [7, 19, 7]
EXAMPLE OUTPUT
[ 3, 4 ]
EXAPLANATION
Given array A = [1, 3, 121, 20, 17, 26, 29]. Let's list down queries:
1. A 1 7 : Number of primes in complete array [1-7] is 3 => 3, 17, 29
2. C 3 19 : Change the number at index-3 to 19. So Array becomes : [1, 3, 19, 20, 17, 26, 29]
3. A 1 7 : Number of primes in complete array [1-7] is 4 => 3, 19, 17, 29
So output : [ 3, 4 ]
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.