Advertisement
Goga21

Untitled

Feb 18th, 2024
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 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.             ans = ans * (l % m);
  20.             v.push_back(l % m);
  21.  
  22.         }
  23.         string s;
  24.         cin >> s;
  25.         for(int i = 0; i < n; i++){
  26.             cout << ans % m << ' ';
  27.             if(ans == 0){
  28.                 continue;
  29.             }
  30.             if(s[i] == 'R'){
  31.                 ans = ans / v.back();
  32.                 v.pop_back();
  33.             }else{
  34.                 ans = ans / v.front();
  35.                 v.pop_front();
  36.             }
  37.         }
  38.         cout << '\n';
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement