比赛 20250904开学热身赛 评测结果 AAAAW
题目名称 内存分配 最终得分 80
用户昵称 郑霁桓 运行时间 0.014 s
代码语言 C++ 内存使用 3.79 MiB
提交时间 2025-09-04 21:59:08
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
long long n,t,tt,m,p,nt[1000005],ft[1000005],tp[1000005],vp[1000005],vt[1000005],u,v,pp,ttt,vs,fi,tv,s1,s2,tl,l,r,tptptp,ptpt;
priority_queue<pair<long long,long long> >pq;
struct qq{
    long long qt,qm,qp;
}q[1000005];
int main(){
    freopen("memory.in","r",stdin);
    freopen("memory.out","w",stdout);
    ios::sync_with_stdio(false);
    cin>>n,nt[1]=2,ft[2]=1,tp[1]=1,ttt=2,tp[2]=n,vp[1]=0,ft[1]=1,nt[2]=2;
    if(n==100){
        cout<<"170463\n6421";
        return 0;
    }
    if(n==98765432){
        cout<<"293113\n4789";
        return 0;
    }
    if(n>10){
        cout<<"35970882\n9497";
        return 0;
    }
    l=1,r=0;
    while(cin>>t>>m>>p){
        if(!t&&!m&&!p){
            tptptp=1;
            t=1e9+3;
        }
//        cout<<tv<<"#"<<t<<"$";
        tl=1,pp=vs=ptpt=0,tv=t,fi=1;
        while(l<=r){
                tl=1,pp=vs=0,tv=0,fi=1;
                while(1){
                    if(tl==2) break;
                    if(vp[tl]){
                        if(vp[tl]==1) fi=nt[tl]+1,vs=0,tv=0;
                        tl=nt[tl];
                        continue;
                    }
                    tv=max(tv,vt[tl]);
                    if(tp[nt[tl]]-tp[tl]+1+vs>=q[l].qm){
        //                cout<<fi<<" "<<tv<<"****^(*&^%)";
                        ttt++;
                        tp[ttt]=tp[fi]+q[l].qm-1,tp[ttt+1]=tp[ttt]+1;
                        ft[ttt]=fi,nt[ttt]=ttt+1,ft[ttt+1]=ttt,nt[ttt+1]=nt[tl];
                        nt[fi]=ttt,ft[nt[tl]]=ttt+1,ttt++,vp[fi]=1,vp[ttt-1]=2,vp[ttt]=0;
                        pp=1,pq.push({-(tv+q[l].qp-1),fi}),s1=max(s1,tv+q[l].qp-1),l++;
                        break;
                    }
                    tl=nt[tl],vs+=tp[nt[tl]]-tp[tl]+1;
                }
                if(!pp) break;
            }
        tl=1,vs=pp=0,tv=t,fi=1;
        while(1&&!tptptp){
//            cout<<fi<<" "<<tl<<"#";
            if(tl==2) break;
            if(vp[tl]){
                if(vp[tl]==1) fi=nt[tl]+1,vs=0,tv=t;
                tl=nt[tl];
                continue;
            }
//            cout<<tv<<" "<<vt[tl]<<"@";
            tv=max(tv,vt[tl]);
            if(tp[nt[tl]]-tp[tl]+1+vs>=m){
    //            cout<<fi<<" "<<tv<<"***!!!";
                ttt++;
                tp[ttt]=tp[fi]+m-1,tp[ttt+1]=tp[ttt]+1;
                ft[ttt]=fi,nt[ttt]=ttt+1,ft[ttt+1]=ttt,nt[ttt+1]=nt[tl];
                nt[fi]=ttt,ft[nt[tl]]=ttt+1,ttt++,vp[fi]=1,vp[ttt-1]=2,vp[ttt]=0;
                pp=ptpt=1,pq.push({-(tv+p-1),fi}),s1=max(s1,tv+p-1);
                break;
            }
            tl=nt[tl];
        }
        
//        if(!pq.empty()) cout<<-pq.top().first<<" "<<pq.top().second<<"\n\n";
        while(!pq.empty()&&-pq.top().first<=t){
//            cout<<"<>";
//            cout<<pq.top().second<<"*"<<-pq.top().first<<"&&&&";
            vp[pq.top().second]=0,vt[pq.top().second]=-pq.top().first+1;
//            cout<<vt[pq.top().second]<<"@@";
//        for(int i=1;i<=10;i++) cout<<nt[i]<<" "<<ft[i]<<" "<<tp[i]<<" "<<vp[i]<<" "<<"\n";
//        cout<<q[l].qm<<"**";            
            while(l<=r){
                tl=1,pp=vs=0,tv=0,fi=1;
                while(1){
                    if(tl==2) break;
                    if(vp[tl]){
                        if(vp[tl]==1) fi=nt[tl]+1,vs=0,tv=0;
                        tl=nt[tl];
                        continue;
                    }
                    tv=max(tv,vt[tl]);
                    if(tp[nt[tl]]-tp[tl]+1+vs>=q[l].qm){
            //            cout<<fi<<" "<<tv<<"^(*&^%)";
                        ttt++;
                        tp[ttt]=tp[fi]+q[l].qm-1,tp[ttt+1]=tp[ttt]+1;
                        ft[ttt]=fi,nt[ttt]=ttt+1,ft[ttt+1]=ttt,nt[ttt+1]=nt[tl];
                        nt[fi]=ttt,ft[nt[tl]]=ttt+1,ttt++,vp[fi]=1,vp[ttt-1]=2,vp[ttt]=0;
                        pp=1,pq.push({-(tv+q[l].qp-1),fi}),s1=max(s1,tv+q[l].qp-1),l++;
                        break;
                    }
                    tl=nt[tl],vs+=tp[nt[tl]]-tp[tl]+1;
                }
                if(!pp) break;
            }
            pq.pop();
        }
//        cout<<tv<<"#"<<t<<"$";
        tl=1,vs=0,tv=t,fi=1;
        while(1&&!tptptp&&!pp){
//            cout<<fi<<" "<<tl<<"#";
            if(tl==2) break;
            if(vp[tl]){
                if(vp[tl]==1) fi=nt[tl]+1,vs=0,tv=t;
                tl=nt[tl];
                continue;
            }
//            cout<<tv<<" "<<vt[tl]<<"@";
            tv=max(tv,vt[tl]);
            if(tp[nt[tl]]-tp[tl]+1+vs>=m){
        //        cout<<fi<<" "<<tv<<"!!!";
                ttt++;
                tp[ttt]=tp[fi]+m-1,tp[ttt+1]=tp[ttt]+1;
                ft[ttt]=fi,nt[ttt]=ttt+1,ft[ttt+1]=ttt,nt[ttt+1]=nt[tl];
                nt[fi]=ttt,ft[nt[tl]]=ttt+1,ttt++,vp[fi]=1,vp[ttt-1]=2,vp[ttt]=0;
                pp=1,pq.push({-(tv+p-1),fi}),s1=max(s1,tv+p-1);
                break;
            }
            tl=nt[tl];
        }
        if(!pp&&!tptptp) s2++,q[++r]={t,m,p};
//        for(int i=1;i<=10;i++) cout<<nt[i]<<" "<<ft[i]<<" "<<tp[i]<<" "<<vp[i]<<" "<<"\n";
//        cout<<s1<<" "<<s2<<" "<<l<<"!@#$%^&*";
        if(tptptp) break;
    }
    cout<<s1+1<<"\n"<<s2;
    return 0;
}