https://www.luogu.com.cn/record/123027155
为什么 T 了?我离 AK 就差这一个点啊……
#include<iostream>
#include<queue>
#define int long long
using namespace std;
int c,t,s[200010];
int head=1,tail=0;
struct node{int x,id,left;}a[200010];
bool operator<(const node &x,const node &y){
return x.x<y.x;
}
priority_queue<node>q;
signed main()
{
cin>>c>>t;
while(t--)
{
int op;
cin>>op;
if(op==1)
{
int x;
cin>>x;
a[++tail]={x,tail,x},s[tail]=s[tail-1]+x;
q.push({x,tail,x});
}
if(op==2)
{
int x;
cin>>x;
while(a[head].left<=x)x-=a[head].left,head++;
a[head].left-=x;
}
if(op==3)
{
int x;
cin>>x;
if(x<=a[head].left)
cout<<a[head].x-a[head].left+x<<endl;
else
{
x-=a[head].left;
int l=head,r=tail,pos=0;
while(l<=r)
{
int mid=(l+r)/2;
if(s[mid]-s[head]<x)l=mid+1,pos=mid;
else r=mid-1;
}
cout<<x-(s[pos]-s[head])<<endl;
}
}
if(op==4)
{
while(q.top().id<head)q.pop();
cout<<q.top().x<<endl;
}
}
return 0;
}