Meowstic to fight, of which has strength . He wants to fight with all of them times. Team Meowstic came to know about this and now they have devised a strategy to battle against the mighty Pikachu.
All the Meowstic stand in a straight line numbered from to . Before every round of battle, they simultaneously use a move, called Helping Hand. It changes the attacking power of Team Meowstic as follows:
- The attacking power of first Meowstic remains .
- The attacking power of the remaining Meowstic changes as where and represents the bitwise OR of and
For example, if the current attacking powers are , after using the Helping Hand, the powers change to , or .
Help Pikachu by finding the attacking powers of all Meowstic when he fights each of them for the last time, that is, for the round.
Note that, the influence of Helping Hand remains forever, and attacking powers DO NOT revert back after any round.
Example:
Input: n = 5, k = 3, arr = {1, 2, 3, 4, 5}
Output: 1 3 3 7 7
Approach
C++
#include <bits/stdc++.h>#define mod 1000000007using namespace std;int main(){long long n = 5, k = 3;long long temp = 0, temp1;vector<long long> arr = {1, 2, 3, 4, 5};if (k > 100){k = 100;}while (k--){temp = 0;for (long long i = 0; i < n; i++){temp1 = arr[i];arr[i] = arr[i] | temp;temp = temp1;}}for (auto i : arr){cout << i << " ";}return 0;}
No comments:
Post a Comment