. Query game (9 100 1 You are given an array A containing distinct integers A-comedy Rinclude stalo. include
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
. Query game (9 100 1 You are given an array A containing distinct integers A-comedy Rinclude stalo. include
Approach • The first query is of type 2, and / and jare 2 and 4 respectively. So you swap A[2], A4). Array A becomes 11, 4, 3, 2, . The second query is of type 3, and x is 2. So you need to output index of 2 in array A, so the output is 4. • The third query is of type 1. So you reverse array A A= [2, 3, 4, 11 • The last query is of type 3, and x is 1. So you need to output index of 1 in array A, so the output is 4. Hence, the answer is (44) Function description Complete the function query_game provided in the editor. This function takes the following 4 parameters and returns the required answer: • N: Represents the size of array A • A: Represents the elements of array A • Q: Represent the number of queries • P: Represents the queries in form of 2D array with rows and 3 columns
Input format Note: This is the input format that you must use to provide custom input (available above the Compile and Test button). • The first line contains T denoting the number of test cases. T also specifies the number of times you have to run the query_game function on a different set of inputs. • For each test case: o The first line contains a single integer N denoting the size of array A. o The second line contains N space-separated values, denoting the elements of A. o The third line contains a single integer Q denoting the number of queries. o Q lines follow, each containing queries in the form of 3 space-separated integers.
Output format For each test case in a new line, print the index of x in array A for each query of type 3 in space-separated format. Constraints 1<T < 105 1<N<2 x 10 1<Q< 2 x 105 1<A < 109 The sum of N and Q across all test cases is < 2 x 105 Code snippets (also called starter code/boilerplate code) This question has code snippets for C, CPP, Java, and Python. Sample input Sample output 1 3 3 1 2 3 3 2 1 2 100 320