Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
- signed main() {
- ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- int t;
- cin >> t;
- while(t--){
- int n, m, ans = 1;
- cin >> n >> m;
- deque<int> v;
- for(int i = 0; i < n; i++){
- int l;
- cin >> l;
- ans = ans * (l % m);
- v.push_back(l % m);
- }
- string s;
- cin >> s;
- for(int i = 0; i < n; i++){
- cout << ans % m << ' ';
- if(ans == 0){
- continue;
- }
- if(s[i] == 'R'){
- ans = ans / v.back();
- v.pop_back();
- }else{
- ans = ans / v.front();
- v.pop_front();
- }
- }
- cout << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement