PROBLEM LINK : Contest Page | CodeChef
Author : salik_anwer
Tester : salik_anwer
Editorialist : mansha15k
Easy to Medium
The Avengers and their allies are currently fighting Thanos in a grand battle. Avengers have found a way to defeat Thanos by combining the energy of his attacks with their own energy. There are “n” Avengers, Energy of the "i"th avenger is “E[i]”. If Thanos attacks “x” times, each time, energy of "i"th avenger becomes E[i] | E[i-1], where 1<=i<=n. " | " represents bitwise OR. Print energy of all Avengers after x attacks from Thanos.
Store the new energies of each avenger back in the array for x no. of times. Display the final array .
For each test case (t), take inputs of “n” and “x” ; followed by the initial energy of each avenger.
New energy of i th avenger = E[i] | E[i-1]; new energy of E remains unchanged.
This is repeated for the no. of attacks of thanos (x), after which the loop terminates.
Final energies are printed.
TIME COMPLEXITY :
using namespace std;
cout<<endl; } return 0;
Feel Free to share and discuss your approach here.