95求助!!!
查看原帖
95求助!!!
1123558
grard4楼主2024/3/31 14:21
#include<bits/stdc++.h>
#define MAXN 500010
using namespace std;
struct node
{
    long long l;
    long long r;
    long long cnt;
};
node a,b[MAXN];
int n,top;
int main()
{
    cin>>n;
    while(n--)
    {
        int op,l,r,k;
        cin>>op;
        if (op==1)
        {
            cin>>l>>r;
            long long c=r-l+1;
            if (top&&l==b[top].r+1)
            {
                b[top].r+=c;
                b[top].cnt+=c;
            }
            else
            {
                b[++top].l=l;
                b[top].r=r;
                b[top].cnt=c;
            }
        }
        else
        {
            cin>>k;
            long long ans=0;
            while(k)
            {
                if (k>=b[top].cnt)
                {
                    k-=b[top].cnt;
                    ans+=(b[top].l+b[top].r)*b[top].cnt/2;
                    top--;
                }
                else
                {
                    ans+=(b[top].r*2-k+1)*k/2;
                    b[top].r-=k;
                    b[top].cnt-=k;
                    break;
                }
            }
            cout<<ans<<"\n";
        }
    }
    return 0;
}
2024/3/31 14:21
加载中...