-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCF1932C.cpp
33 lines (33 loc) · 872 Bytes
/
CF1932C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <bits/extc++.h>
using namespace std;
namespace pbds = __gnu_pbds;
using ui = unsigned int;
using uli = unsigned long long int;
using li = long long int;
using usi = unsigned short int;
int main(void) {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
size_t T;
cin >> T;
while (T--) {
size_t n;
usi m;
cin >> n >> m;
deque<usi> q(n);
for (usi& i : q) cin >> i;
vector<usi> stk;
for (size_t i = 0; i < n; ++i) {
char c;
cin >> c;
stk.push_back(c == 'L' ? q.front() : q.back()),
c == 'L' ? q.pop_front() : q.pop_back();
}
ui t = 1;
vector<usi> ans;
for_each(stk.crbegin(), stk.crend(),
[&ans, &t, m](usi x) { ans.push_back((t *= x) %= m); });
for_each(ans.crbegin(), ans.crend(), [](usi x) { cout << x << ' '; });
cout.put('\n');
}
return 0;
}