莫名其妙的错误 求帮助!
查看原帖
莫名其妙的错误 求帮助!
866688
AlenLuo楼主2024/5/4 18:30

这是代码

#include<bits/stdc++.h>
using namespace std;
int m,l,r,k,h,n;
stack<int>stk;
int main(){
    
    cin>>n;
    while(cin>>m){
        if(m==1){
            cin>>l>>r;
            stk.push(l);
            stk.push(r);
        }
        if(m==2){
            cin>>k;
            h=0;
            while(k>0){
                if(!stk.empty()){
                    r=stk.top();
                    stk.pop();
                    l=stk.top();
                    stk.pop();
                }
                if(r-l+1<=k){
                    k-=r-l+1;
                    h+=(l+r)*(r-l+1)/2;
                }
                else{
                    h+=(r+(r-k+1))*(k)/2;
                    stk.push(l);
                    stk.push(r-k);
                    k=0;
                }
            }
            cout<<h<<endl;
        }
    }
    return 0;
}
2024/5/4 18:30
加载中...