蒟蒻求助,75pts,1个RE4个WA
查看原帖
蒟蒻求助,75pts,1个RE4个WA
820529
LimitTimeAC楼主2022/11/11 23:45

代码如下:

#include<bits/stdc++.h>
using namespace std;
 
long long n, tl, tr, tk, type; 

class Lr{ 
    public:
        Lr() = default;
        Lr(int xl, int xr):
            l(xl), r(xr){} 
        int l, r;
        int getNum(){
            return this->r-this->l+1;
        } 
        int getSum(){
            return ((this->l+this->r) * this->getNum())/2;
        } 
};

stack<Lr> st; 

int main(){
    cin>>n; 
    while(n--){ 
        cin>>type; 
        if(type==1){ 
            cin>>tl>>tr; 
            st.push(Lr(tl, tr)); 
        }else{ 
            cin>>tk; 
            int now=0, sumn=0; 
            while(now<tk){ 
                if(now+st.top().getNum()<=tk){ 
                    now += st.top().getNum();
                    sumn += st.top().getSum(); 
                    st.pop(); 
                }else{ 
                    int t = tk-now; 
                    int r = st.top().r; 
                    sumn += (r-t+1 + r)*t/2; 
                    st.top().r = r-t; 
                    break; 
                }
            }
            cout<<sumn;
            cout<<endl; 
        }
    }
    return 0;
}

评测记录:记录详情 有大佬能看一下嘛?谢啦

2022/11/11 23:45
加载中...