Advertisement
Ankit_132

C

Feb 20th, 2024
949
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int t;
  7.     cin>>t;
  8.    
  9.     while(t--){
  10.         int n, m;
  11.         cin>>n>>m;
  12.        
  13.         deque<int> a;
  14.         for(int i=0; i<n; i++)
  15.         {
  16.             int x;
  17.             cin>>x;
  18.             a.push_back(x);
  19.         }
  20.        
  21.         string s;
  22.         cin>>s;
  23.        
  24.         vector<int> v;
  25.        
  26.         for(int i=0; i<n; i++)
  27.         {
  28.             if(s[i] == 'L')
  29.             {
  30.                 v.push_back(a.front());
  31.                 a.pop_front();
  32.             }
  33.             else
  34.             {
  35.                 v.push_back(a.back());
  36.                 a.pop_back();
  37.             }
  38.         }
  39.        
  40.         reverse(v.begin(), v.end());
  41.        
  42.         vector<int> ans;
  43.         int mul = 1;
  44.        
  45.         for(auto e: v)
  46.         {
  47.             mul *= e;
  48.             mul %= m;
  49.             ans.push_back(mul);
  50.         }
  51.        
  52.         reverse(ans.begin(), ans.end());
  53.        
  54.         for(auto e: ans)
  55.             cout<<e<<" ";
  56.         cout<<"\n";
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement