LR-remainders
网站:https://www.luogu.com.cn/problem/CF1932C
https://codeforces.com/problemset/problem/1932/C
离线处理思想,分配id和val
先读入一整行输入,然后按照处理顺序给每个字母打上id
sort:注意,按照id从大到小来排,因为后面的数不需要前面的,然后用栈就行
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<sstream>
#include<string>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<map>
#include<queue>
#include<limits.h>
#include<climits>
#include<fstream>
#include<stack>
#include<set>
typedef unsigned long long ll;
using namespace std;
const int N = 2e5 + 10;
struct each
{
ll val, id;
}ealst[N];
bool cmp(each a, each b) { return a.id > b.id; }
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t; cin >> t;
while (t--)
{
ll n, m; string s;
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> ealst[i].val;
cin >> s;
int l = 0, r = n - 1;
for (int i = 0; i < s.length(); i++)
{
if (s[i] == 'L')
ealst[l++].id = i;
else
ealst[r--].id = i;
}
stack<ll>qa;
sort(ealst, ealst + n, cmp);
ll ans = 1;
for (int i = 0; i < n; i++)
{
ans *= ealst[i].val;
ans %= m;
qa.push(ans);
}
while (!qa.empty()) { cout << qa.top() << ' '; qa.pop(); }
cout << endl;
}
return 0;
}

浙公网安备 33010602011771号