#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int a[N],tmp[N];
priority_queue<int> big;
priority_queue<int,vector<int>,greater<int>> small;
int ksm(int a,int b){
if(b==0){
return 1;
}
int t=ksm(a,b/2);
if(b&1){
return t*t%317847191*a%317847191;
}
else{
return t*t%317847191;
}
}
int main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
big.push(a[i]);
small.push(a[i]);
}
while(m--){
char c;
cin>>c;
if(c=='S'){
cout<<big.top()<<endl;
}
if(c=='B'){
cout<<small.top()<<endl;
}
if(c=='M'){
cout<<ksm(big.top(),small.top())<<endl;
}
if(c=='T'){
int sum=1,m=big.size();
for(int i=1;i<=m;i++){
sum*=big.top();
tmp[i]=big.top();
big.pop();
}
for(int i=1;i<=m;i++){
big.push(tmp[i]);
}
cout<<sum%317847191<<endl;
}
if(c=='D'){
int x,m=big.size();
cin>>x;
bool flag=0;
for(int i=1;i<=m;i++){
if(big.top()==x&&!flag){
flag=1;
m--;
continue;
}
tmp[i]=big.top();
}
while(!small.empty()){
small.pop();
}
for(int i=1;i<=m;i++){
big.push(tmp[i]);
small.push(tmp[i]);
}
}
}
return 0;
}
我认为是删除操作不对,希望有大佬帮助改正