45分TLE求调
查看原帖
45分TLE求调
374263
Miku_Sama楼主2024/8/12 16:30

45分代码求调

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long ll;
map<ll,ll>a;
ll c,q,tail=1,head=1;
void do1(ll x){
    a[tail]=1;
    a[tail+1]=x;
    tail+=2;
//    for(int i=head;i<tail;i++){
//        cout<<a[i]<<" ";
//    }
//    cout<<endl;
    return ;
}
void do2(ll y){
    ll tmp;
    while(y!=0){
        tmp=a[head+1]-a[head]+1;
        if(tmp<=y){
            a[head]=0;
            a[head+1]=0;
            head+=2;
            y-=tmp;
        }else{
            a[head]+=y;
            return;
        }
    }
}
ll do3(ll z){
    ll tmp,tnp=head;
    while(z!=0){
        tmp=a[tnp+1]-a[tnp]+1;
        if(tmp<z){
            z-=tmp;
            tnp+=2;
        }else if(tmp==z){
            return a[tnp+1];
        }else{
            return a[tnp]+z-1;
        }
    }
}
ll do4(){
    ll maxx=0;
    for(int i=head+1;i<tail;i+=2){
        maxx=max(maxx,a[i]);
    }
    return maxx;
}
int main(){
    cin>>c>>q;
    ll cz;
    while(q--){
        cin>>cz;
        if(cz==1){
            cin>>cz;
            do1(cz);
        }else if(cz==2){
            cin>>cz;
            do2(cz);
        }else if(cz==3){
            cin>>cz;
            cout<<do3(cz)<<endl;
        }else{
            cout<<do4()<<endl;
        }
    }
    return 0;
}

2024/8/12 16:30
加载中...