Codeforces Round 907 (Div. 2) 1891B - Deja Vu Solution


 

 Problem Link: https://codeforces.com/problemset/problem/1891/B

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. while (t--) {
  10. int n , q ; cin >> n >> q ;
  11. vector<int>a(n) ;
  12. for ( int i = 0 ; i < n ; i++){
  13. cin >> a[i] ;
  14. }
  15. int value = 34 ;
  16. while(q--){
  17. int x ; cin >> x ;
  18. if ( x >= value ) continue ;
  19. for ( int i = 0 ; i < n ; i++){
  20. if(a[i]%(1<<x) == 0){
  21. a[i] |= (1<<(x-1));
  22. }
  23. }
  24. value = x ;
  25. }
  26. for ( auto i : a){
  27. cout << i <<" ";
  28. }
  29. cout << "\n";
  30. }
  31. return 0 ;
  32. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.