Soulful Operations

All submissions for this problem are available.
**So far so good, continue, we should?** If you've witnessed your dreams come true, then this is perhaps the place where you should be. An interesting,and perhaps lifechanging quest lies in store. Is the fulfillment of all your wishes the only real source of happiness? Is materialistic happiness the only way to go about things? The loss of a loved one leaves an indelible scar in the now void terrain of one's life. Being endowed with the power to restore the life of another can be amazing, yet deadly if left in the wrong hands. Read on if you are moved by this. Thanos has decided that come what may, he will obtain the soul stone irrespective of it's cost. Thus Gamora is forced to make the one final jump, betraying all trust she had on her father. The souls of Vormir feel bad for Gamora and decide to give her a chance to survive. They warn Thanos that unless he solves this task, the soul stone will be destroyed by them forever. The souls show Thanos a set of **2^{N}** values, called their **emotional disturbance parameters**. They also provide Thanos with two codes, $a$ and $b$, which correspond to the following operations:  1 : **bitwise AND**  2 : **bitwise OR**  3 : **bitwise XOR**  4: **addition**  5: **multiplication modulo (10^{9}+7)**  6: **exponentiation modulo (10^{9}+7)** **IMPORTANT NOTE:**: For this question, you are asked to assume that **0^{0} = 1**. Thanos must systematically apply these operations in an **alternating fashion** on adjacent terms in the set of emotional disturbance parameters. He obtains a new sequence of half the size, and continues this operation until he obtains a **single term**, called the **effective emotional disturbance**. For example: if the set is **{1,3,5,7}** and the opcodes are 1 and 2, the operations are as follows: First sequence = **{1 AND 3,5 AND 7} = {1 , 5}** Second sequence = **{1 OR 5}** = **{5}**. Hence the **effective emotional disturbance** will be 5 in this case. The souls argue among each other, and thus, they give Thanos $Q$ queries, where in each query, they ask him to update the value occuring at index $i$ to another value of their choice. After **every** query, Thanos must report the **effective emotional disturbance** in a timely fashion. You need the soul stone, to bring back your programming soul that you've longed to find. Need any more hints be provided? ###Input format: The first line contains $T$, the number of test cases. Each testcase is described as follows: The first line of the test case contain two space separated integers, $N$, the number as described by the souls, and $Q$, the number of queries. The next line contains **2^{N}** space separated integers, the emotional disturbances of the souls. The next line contains two space separated integers $a$ and $b$, the codes. The next $Q$ lines contain 2 integers each, $i$ and $x$, meaning that the value of the **i^{th}** disturbance should be changed to $x$. ###Output format: Print $Q$ lines for each test case, the answer to each query by the souls. ###Constraints: $1$ $\leq$ $T$ $\leq$ $5$ $1$ $\leq$ $N$ $\leq$ $17$ $1$ $\leq$ $Q$ $\leq$ **10^{5}** $1$ $\leq$ **a,b** $\leq$ $6$ $1$ $\leq$ $i$ $\leq$ **2^{N}** $0$ $\leq$ **values of emotional disturbance** $\leq$ **2 x 10^{9}** ###Sample input 1 2 4 1 6 3 5 2 3 1 4 3 4 1 2 1 2 ###Sample output: 1 3 3 3Author:  bluishgreen 
Tags  bluishgreen 
Date Added:  20122018 
Time Limit:  1  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions