题目描述
给定一个初始为空的序列w和一个长度为m单调递增序列a。对序列w作如下n次操作:
(1)操作0,在序列尾部添加数字0。
(2)操作1,在序列尾部添加数字1。
(3) 操作-1,删除序列w中所有位于位置ai的数(1<=i<=m)。比如a={1,3,5},就将w中第1,3,5个数删除。若ai>w的当前长度,则该操作停止。输出n次操作后的序列w。
输入
第一行为两个数n与m,表示操作数与a的长度,1 ≤ n, m ≤ 10^6。
第二行为m个数,表示序列a,ai<=10^6。
后面共有n行,每行有一个整数(0/1/-1),表示操作类型。
输出
最终的序列w。若序列为空,输出Poor stack!
样例输入
10 3
1 3 6
-1
1
1
0
0
-1
0
1
-1
1
样例输出
011
题目来源:2020安徽省省赛
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t,n;
cin >> t >> n;
int a[n];
for(int i=0;i<n;i++)cin >> a[i];
string s = "";
while(t--){
int op,k = 0;
cin >> op;
if(op == 0)s = s + "0";
else if(op == 1)s = s + "1";
else {
for(int i=0;i<n;i++){
if(a[i]+k > s.length())break;
s.erase(s.begin() - 1 + a[i] + k);
k--;
}
}
}
if(s.length() == 0)cout << "Poor stack!";
else cout << s;
return 0;
}