如题,希望有人能帮忙看看(
#include <bits/stdc++.h>
#define int long long
using namespace std;
inline long long read() {
long long x;bool f;char ch;
for(f=0;!isdigit(ch=getchar());f=ch=='-');
for(x=ch-48;isdigit(ch=getchar());x=x*10+ch-48);
return f?-x:x;
}
inline void print(long long x,char las) {
if(!x) {
putchar(48),putchar(las);
return ;
}
if(x<0) putchar('-'),x=-x;
char ls[25];int k=0;
while(x) ls[++k]=x%10+48,x/=10;
while(k) fwrite(ls+k,1,1,stdout),k--;
fwrite(&las,1,1,stdout);
return ;
}
struct node {
int x,name;
inline bool operator<(const node&nw) const {
return x>nw.x;
}
}nd[300005];
struct ad {
long long x,delet;int name;
}add[300005];long long hd,qz[300005];int head=1,tail=1;
set<node>st;
int c=read(),q=read(),cnt=0;
inline int query(long long x) {
int l=0,r=tail;
while(l<=r) {
int mid=(l+r)>>1;
if(qz[mid]>=x) r=mid-1;
else l=mid+1;
}
return r;
}
signed main() {
while(q--) {
int opt=read();
if(opt==1) {
long long x=read();
add[tail].x=x;add[tail].name=cnt++;add[tail].delet=0;
node ls;ls.x=x,ls.name=cnt-1;
st.insert(ls);
qz[tail]=add[tail].x+qz[tail-1];tail++;
}else if(opt==2) {
long long y=read();hd+=y;
while(y) {
if(add[head].x-add[head].delet<=y) {
y-=(add[head].x-add[head].delet);node ls;ls.x=add[head].x,ls.name=add[head].name;
set<node>::iterator it=st.lower_bound(ls);
st.erase(it);head++;
}else add[head].delet+=y,y=0;
}
}else if(opt==3) {
int qu=read()+hd,dd=qu-qz[query(qu)];
print(dd,'\n');
}else print(st.begin()->x,'\n');
}
return 0;
}