Ankit_132

B

Oct 30th, 2023
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll     long long
  6. #define pb     push_back
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8.  
  9. int main()
  10. {
  11.     _test
  12.     {
  13.         int n, q;
  14.         cin>>n>>q;
  15.  
  16.         vector<ll int> a(n), x(q);
  17.  
  18.         for(auto &e: a)     cin>>e;
  19.         for(auto &e: x)     cin>>e;
  20.  
  21.         vector<vector<int>> div(31);
  22.  
  23.         vector<int> done(n);
  24.  
  25.         for(int b=30; b>=0; b--)
  26.         {
  27.             for(int i=0; i<n; i++)
  28.             {
  29.                 if(done[i])     continue;
  30.  
  31.                 if((a[i]%(1ll<<b)) == 0)
  32.                 {
  33.                     done[i] = 1;
  34.                     div[b].pb(i);
  35.                 }
  36.             }
  37.         }
  38.  
  39.         for(auto e: x)
  40.         {
  41.             for(int b=e; b<=30; b++)
  42.             {
  43.                 for(auto i: div[b])
  44.                 {
  45.                     div[e-1].pb(i);
  46.                     a[i] += (1ll<<(e-1));
  47.                 }
  48.  
  49.                 div[b].clear();
  50.             }
  51.         }
  52.  
  53.         for(auto &e: a)     cout<<e<<" ";
  54.         cout<<"\n";
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment