P1486
偷懒的新方法
但vector足以
#include<bits/stdc++.h>
using namespace std;
vector<int>v;
inline int read() {
char ch=getchar();
int x=0,f=1;
for(; !isdigit(ch); ch=getchar())if(ch=='-')f=-1;
for(; isdigit(ch); ch=getchar())x=x*10+ch-'0';
return x*f;
}
int main() {
register int n,minn=0,tot=0;
n=read(),minn=read();
v.reserve(1000010);
for(register int i=1; i<=n; i++) {
char ch;
cin>>ch;
register int k=read();
if(ch=='I') {
if(k<minn)
continue;
v.insert(lower_bound(v.begin(),v.end(),k),k);
}
if(ch=='A') {
register int s=v.size();
for(register int i=0; i<s; i++)
v[i]+=k;
}
if(ch=='S') {
register int s=v.size();
for(register int i=0; i<s; i++) {
v[i]-=k;
if(v[i]<minn)
v.erase(lower_bound(v.begin(),v.end(),v[i])),i--,tot++,s--;
}
}
if(ch=='F') {
register int s=v.size();
if(k>s)
cout<<-1<<"\n";
else
cout<<v[s-k]<<"\n";
}
}
cout<<tot;
return 0;
}