双端队列模拟过程即可,很像2013华中网络预赛的某题。。。
好像是D
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<cmath>
#include<vector>
#include<deque>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define nMax 1010
#define inf 0x7fffffff
#define LL long long
#define pb push_back
struct BB{
char s[5];
void read(){
scanf("%s",s);
}
void read(char *str){
sscanf(str,"ADD(%s",s);
s[strlen(s)-1]='\0';
}
};
int k;
deque<BB> que;
bool ok;
vector<BB> ans;
void ADD(BB a){
if(ok) que.push_front(a);
else que.push_back(a);
if(que.size() > k ){
if(ok) {
ans.push_back(que.back());
que.pop_back();
}
else {
ans.push_back(que.front());
que.pop_front();
}
}
return ;
}
void Rotate(){
ok ^= true;
}
void POP(){
if(ok) {
while(!que.empty()){
ans.push_back(que.back());
que.pop_back();
}
}else{
while(!que.empty()){
ans.push_back(que.front());
que.pop_front();
}
}
}
int main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
int n,m;
while(~scanf("%d%d%d",&n,&m,&k)){
while(!que.empty()) que.pop_front();
ans.clear();
ok = false;
BB a;
for(int i=0;i<n;i++) {
a.read();
que.push_back(a);
}
while(que.size() > k) {
ans.push_back(que.back());
que.pop_back();
}
ok ^= true;
char Cmd[1010];
for(int i=0;i<m;i++){
scanf("%s",Cmd);
if(Cmd[0] == 'A'){
a.read(Cmd);
ADD(a);
}else {
Rotate();
}
}
POP();
for(int i=ans.size()-1;i>=0;i--){
printf("%s\n",ans[i].s);
}
}
return 0;
}