Codeforces Round 907 (Div. 2) 1891B - Deja Vu Solution
Problem Link: https://codeforces.com/problemset/problem/1891/B
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n , q ; cin >> n >> q ;
- vector<int>a(n) ;
- for ( int i = 0 ; i < n ; i++){
- cin >> a[i] ;
- }
- int value = 34 ;
- while(q--){
- int x ; cin >> x ;
- if ( x >= value ) continue ;
- for ( int i = 0 ; i < n ; i++){
- if(a[i]%(1<<x) == 0){
- a[i] |= (1<<(x-1));
- }
- }
- value = x ;
- }
- for ( auto i : a){
- cout << i <<" ";
- }
- cout << "\n";
- }
- return 0 ;
- }
No comments