Advertisement
Goga21

Untitled

Feb 18th, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define int long long
  4.  
  5. using namespace std;
  6.  
  7.  
  8. signed main() {
  9.     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  10.     int t;
  11.     cin >> t;
  12.     while(t--){
  13.         int n, m, ans = 1;
  14.         cin >> n >> m;
  15.         deque<int> v;
  16.         for(int i = 0; i < n; i++){
  17.             int l;
  18.             cin >> l;
  19.             v.push_back(l);
  20.             ans *= l;
  21.         }
  22.         string s;
  23.         cin >> s;
  24.         for(int i = 0; i < n; i++){
  25.             cout << ans % m << " ";
  26.             if(s[i] == 'R'){
  27.                 ans = ans / v.back();
  28.                 v.pop_back();
  29.             }else{
  30.                 ans = ans / v.front();
  31.                 v.pop_front();
  32.             }
  33.         }
  34.         cout << '\n';
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement