. Query game (9 100 1 You are given an array A containing distinct integers A-comedy Rinclude stalo. include

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
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

Post by answerhappygod »

Query Game 9 100 1 You Are Given An Array A Containing Distinct Integers A Comedy Rinclude Stalo Include Stdbool In 1
Query Game 9 100 1 You Are Given An Array A Containing Distinct Integers A Comedy Rinclude Stalo Include Stdbool In 1 (27.7 KiB) Viewed 175 times
Query Game 9 100 1 You Are Given An Array A Containing Distinct Integers A Comedy Rinclude Stalo Include Stdbool In 2
Query Game 9 100 1 You Are Given An Array A Containing Distinct Integers A Comedy Rinclude Stalo Include Stdbool In 2 (40.24 KiB) Viewed 175 times
Query Game 9 100 1 You Are Given An Array A Containing Distinct Integers A Comedy Rinclude Stalo Include Stdbool In 3
Query Game 9 100 1 You Are Given An Array A Containing Distinct Integers A Comedy Rinclude Stalo Include Stdbool In 3 (67.42 KiB) Viewed 175 times
Query Game 9 100 1 You Are Given An Array A Containing Distinct Integers A Comedy Rinclude Stalo Include Stdbool In 4
Query Game 9 100 1 You Are Given An Array A Containing Distinct Integers A Comedy Rinclude Stalo Include Stdbool In 4 (35.11 KiB) Viewed 175 times
. Query game (9 100 1 You are given an array A containing distinct integers A-comedy Rinclude stalo. include<stdbool. include malloc. You are also given Q queries of the form • To Reverse the array A . 2//Swap the elements AW and All • 3x0 Print the position of element in array A Inte query game (int n, int A. int 0. Inte P. Inta outs C // write your code here 7 } Task Print the position of x in array A after each query of type 3 int main() { int out_ni int T scanf("d", GT): for(int i = 0; i < Ti t_1+1 Note: l-based indexing is followed 10 11 12 13 14 15 16 17 18 19 Example Assumptions E N; scanf("d", o); int is: int A (int) malloc(sizeofantle)); ALAMAL • N4 111 vscode Submit code . A = 2 3 4 • 0-4 Queries [224][320111001/3101 M Compile & Tostcode Test against custom input Custom input populated

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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply