## Inaho VII

View as PDF

Points: 25 (partial)
Time limit: 2.5s
Memory limit: 256M

Author:
Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Inaho is finally home! After being stuck in an -dimensional for so long, he has started to comprehend the complexities of dimensions and have thought of a problem. Unfortunately, he does not know of a solution as he is not yet a master of dimensions, so he has asked you for help.

Given an -dimensional array, and a type of operation:

Type operation: print the normal array given the Binary Indexed Tree.

Type operation: print the Binary Indexed Tree given the normal array.

#### Input Specification

The first line will contain two space-separated integers , and , the number of dimensions and the type of operation respectively.

The second line will contain space-separated integers , which are the values in the array. If , this array is the Binary Indexed Tree, and if , this array is the normal array.

represents the value at position where .

In other words, the second line will be a flattened -dimensional grid.

#### Output Specification

The normal array, if the , or the Binary Indexed Tree, if .

The output should follow the same format as the second line of the input. That is, the integer should represent the value at where .

No further constraints.

#### Sample Cases Note

For the sake of not having 10 million characters in the sample cases and for the sample cases to be useful, . In the actual test cases, however, will follow the constraints as stated in the Input Specification (that is, ).

#### Sample Input 1

1 1
1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 16 1 2 1 4

#### Sample Output 1

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

#### Sample Input 2

2 2
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

#### Sample Output 2

1 2 1 4 2 4 2 8 1 2 1 4 4 8 4 16

#### Sample Input 3

4 1
1 9 3 2 4 7 5 8 2 9 1 8 4 9 2 10

#### Sample Output 3

1 8 2 -9 3 -5 -1 9 1 -1 -3 9 -1 3 0 -6