
setAllTrue(): Sets all the indicies to true
setAllFalse(): Sets all the indices to false
setIndexTrue(index): Set the value at position index to true
setIndexFalse(index): Set the value at position index to False
getIndex(index): Return the value of position index
Initially, all the values of the data structure are set to false.
The Queries are in the format below-:
(1, index, value): Set the value at the given index
(2, index): Get the value at the given index
(3, value): Set all the indices to the boolean value given.
The value 1 represents true and 0 represents false.
You are given Q = [[1, 2, 1], [3, 0], [2, 4]], Here
Q[0] is the query that sets the boolean value at index 2 to True.
Q[1] is the query that sets the value of all indices to False.
Q[2] is the query that gets the value at index 4 that is False.
Hence the answer is [False].
The first line of input contains the integer ‘T’ representing the number of test cases.
The second line of input contains a single integer ‘Q’, representing the number of queries.
The next ‘Q’ lines contain space-separated integers denoting the queries.
For each test case, print the list of boolean in separate lines representing the output of the queries.
Print a separate line for each test case.
1 <= T <= 10
2 <= Q <= 10^6
1 <= index <= 10^5
Time Limit: 1 sec
You do not need to print anything. It has already been taken care of. Just implement the function.
In this approach, we will maintain an array of max size with all initial values set to false. Then we will change the value of the array in each of the functions
Algorithm:
In this approach, we will maintain a HashMap and add all the indexes to value to the hashmap, but setting all indices true or false will take linear time. So to counter this, we will delete the entire HashMap and change the default value of the hashmap as true or false accordingly.
Algorithm: