链表,模拟。
写一个双向链表模拟一下过程。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c=getchar(); x=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) {x=x*+c-''; c=getchar();}
} const int maxn=;
struct X
{
bool f;
int nx,pr;
}s[maxn]; char t[maxn],op[maxn];
int n,m,p;
stack<int>S;
int flag[maxn];
int f1[maxn],f2[maxn]; int main()
{
scanf("%d%d%d",&n,&m,&p); p--;
scanf("%s",t); int len=strlen(t); for(int i=;t[i];i++)
{
if(S.empty()) S.push(i);
else
{
if(t[i]=='(') S.push(i);
else
{
if(t[S.top()]=='(')
{
f1[S.top()]=i, f2[i]=S.top();
S.pop();
}
else S.push(i);
}
}
} for(int i=;i<len;i++)
{
if(t[i]=='(') s[i].f=; else s[i].f=;
s[i].pr=s[i].nx=-;
if(i!=) s[i].pr=i-; if(i!=len-) s[i].nx=i+;
} scanf("%s",op);
for(int i=;op[i];i++)
{
if(op[i]=='L') p=s[p].pr;
else if(op[i]=='R') p=s[p].nx;
else
{
int pos1=p,pos2;
if(s[p].f==) pos2=f1[p]; else pos2=f2[p];
if(pos1>pos2) swap(pos1,pos2); // for(int j=pos1;j<=pos2;j++) flag[j]=1;
flag[pos1]++;
flag[pos2+]--; if(s[pos1].pr!=-) s[s[pos1].pr].nx=s[pos2].nx;
if(s[pos2].nx!=-) s[s[pos2].nx].pr=s[pos1].pr; if(s[pos2].nx!=-) p=s[pos2].nx;
else p=s[pos1].pr; }
} LL sum=; // for(int i=0;i<len;i++) printf("%d ",flag[i]);
// printf("\n");
for(int i=;i<len;i++)
{
sum=sum+flag[i];
if(sum>) continue;
printf("%c",t[i]);
}
printf("\n");
return ;
}